terraform-patterns
/terraform-patterns
Use when designing Terraform modules, managing state backends, reviewing IaC for security or anti-patterns, implementing multi-region deployments, or standardising Terraform CI/CD. Triggers on ".tf files", "Terraform module", "remote state", "IaC review", "Terraform security", or "multi-region infra".
Assessment and security
- Files in this package
- 1
- Scripts
- 0
- HTML comments
- 0
- URLs in SKILL.md
- 0
No signals detected. Repository changed on 29.09.2026, without references to retired models or APIs.
Apache-2.0, otwarta: można używać i zmieniać, z zachowaniem licencji i informacji o zmianach.
What it does and when to use it
Use when designing Terraform modules, managing state backends, reviewing IaC for security or anti-patterns, implementing multi-region deployments, or standardising Terraform CI/CD. Triggers on ".tf files", "Terraform module", "remote state", "IaC review", "Terraform security", or "multi-region infra".
Triggers from the description
Original author description
Use when designing Terraform modules, managing state backends, reviewing IaC for security or anti-patterns, implementing multi-region deployments, or standardising Terraform CI/CD. Triggers on ".tf files", "Terraform module", "remote state", "IaC review", "Terraform security", or "multi-region infra".
How it works
- Layout (HashiCorp style guide)
- Procedure
- Verification
- Review checklist (concrete defects only)
- Capture lore
SKILL.md preview
---
name: terraform-patterns
description: Use when designing Terraform modules, managing state backends, reviewing IaC for security or anti-patterns, implementing multi-region deployments, or standardising Terraform CI/CD. Triggers on ".tf files", "Terraform module", "remote state", "IaC review", "Terraform security", or "multi-region infra".
stack: [terraform]
area: infra
---
# Write predictable, secure Terraform
Terraform changes real infrastructure, and its state file is a shared, lock-protected
database that also holds secrets in plaintext. Follow HashiCorp's style guide and module
guidance; verify with `fmt`, `validate` and `terraform test`; never apply from an agent
session.
## Layout (HashiCorp style guide)
```
terraform.tf # terraform { required_version, required_providers }
providers.tf # provider blocks — ROOT modules only
backend.tf # backend config — root only
main.tf # resources and data sources (split by concern when large: network.tf …)
variables.tf # alphabetical; type, description, default?, sensitive?, validation
outputs.tf # alphabetical; description, value, sensitive?
locals.tf
modules/<name>/ # local child modules, same layout minus providers/backend
```
Names are descriptive snake_case nouns without the type (`aws_instance.web_api`, not
`aws_instance.web-api-instance`).
## Procedure
1. **Read what exists.** `search_lore` for backend, naming, tagging and module
conventions. Read the root modules, `.terraform.lock.hcl`, CI jobs and any policy
(tflint, checkov, trivy config). Extend the existing module style.
2. **Design the module interface.** One module = one coherent concern. Every variable has
`type` and `description`; optional ones have a sensible `default`; secrets set
`sensitive = true`; `validation` blocks only for real invariants. Outputs are the
minimum callers need, each with a `description`. Child modules declare
`required_providers` with a minimum version (`>=`) and **never** contain `provider`
blocks; the root pins providers (`~>` or exact) and commits `.terraform.lock.hcl`.
3. **Write resources safely.**
- `for_each` keyed by stable names for collections of distinct things; `count` only for
on/off. Index-shifting `count` lists destroy and recreate resources.
- Stateful resources (databases, buckets, KMS keys) get
`lifecycle { prevent_destroy = true }`.
- Refactors use `moved` blocks (and `removed`/`import` blocks) instead of manual
`terraform state mv`, so the plan shows no destroy.
- Least-privilege IAM (no `"*"` actions or resources without a written reason),
encryption at rest and in transit, no public buckets, no `0.0.0.0/0` on admin ports.
- Tags via provider `default_tags` where supported: environment, owner, managed-by.
4. **State and locking.** Remote backend with locking and encryption; for S3 use
`use_lockfile = true` (Terraform ≥ 1.11; DynamoDB locking is deprecated). Separate state per environment
(directory or workspace), and restrict who can read state — `sensitive` hides values in
plan output, not in state. Share data across states with data sources or
`terraform_remote_state` outputs, not whole-state access.
5. **Respect the lock.** Never pass `-lock=false`. Never `terraform force-unlock` unless you
have proven the holder process is gone (not merely slow or paused) — breaking a live
holder's lock is the concurrent-writer bug that lost acknowledged writes in live runs,
and here it corrupts state. Use `-lock-timeout=5m` in CI instead.
6. **Credentials.** From the environment or OIDC/dynamic credentials — never in `.tf`,
`.tfvars` committed to git, or provider blocks.
7. **CI.** On PR: `fmt -check`, `validate`, `terraform test`, security scan, and `plan`
posted for review. Apply only from the protected default branch, one run per state at a
time.
8. **Verify** (below), evidence each acceptance criterion with the `record-evidence`
skill, then stop. Do not run `plan`, `apply` or `destroy`: they reach the cloud with
whatever ambient credentials the host holds (`~/.aws`, gcloud). If an AC needs a real
plan, state in evidence that a human must run it, or `mark_ticket_blocked`.
## Verification
- `terraform fmt -check -recursive` — clean.
- `terraform validate` only where the module is already initialised (`.terraform/`
present and gitignored). Never run `terraform init`: it downloads providers and modules
(with the host's ambient credentials for remote module sources) and rewrites
`.terraform.lock.hcl`. If validate cannot run, say so in evidence.
- `terraform test`, in an already-initialised module, with `.tftest.hcl` files that `mock_provider` every provider
(Terraform 1.7+): these cover variable validation, conditional resources, and
computed names without the cloud. Never run an unmocked test: the default
`command = apply` creates real resources. Add a test per AC behaviour.
- `tflint`, `checkov -d .` or `trivy config .` if installed; no HIGH/CRITICAL findings.
- When a human supplies a plan (for example CI output): no unexpected `destroy` or
`-/+` replace actions.
## Review checklist (concrete defects only)
- `provider` block inside a child module; missing version constraints or lock file.
- Variable without type/description; secret without `sensitive`; secret in committed tfvars.
- `count` over a list of distinct items; rename without a `moved` block (plan destroys).
- Stateful resource without `prevent_destroy`.
- Wildcard IAM, public bucket, open admin ingress, unencrypted storage.
- Local state, no locking, `-lock=false`, or an unconditional `force-unlock` in scripts.
## Capture lore
Backend layout, naming and tagging policy, and approved module sources are high-value
lore: call `suggest_lore` with `tags: [terraform, infra, iac]`.
Versions
| Repository | Score | Licence |
|---|---|---|
| This page · tmj-90/gaffer | 100 | Apache-2.0 |
| borghei/Claude-Skills | 100 | MIT |
| j4flmao/agent-skills | 100 | MIT |
| LeoYeAI/openclaw-master-skills | 100 | MIT |
| 420company/artemis | 95 | MIT |
| alirezarezvani/claude-skills | 95 | MIT |
Database snapshot: 13.11.2026 · package version 4f0a02c41289 (SHA-256 digest of the entire package)
Downloads in the last 30 days: 1 · ranking
Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.
Similar skills
- 95terraform-state
Use when managing Terraform state files, remote backends, and state locking for infrastructure coordination. - 100terraform-iac
Manages cloud infrastructure using Terraform (and OpenTofu). Use when the user wants to write Terraform configurations, provision cloud resources, manage state, create modules, set up multi-environment deployments, import existing infrastructure, debug plan/apply errors, migrate… - 100terraform-iac-expert
Expert in Infrastructure as Code using Terraform and OpenTofu. Specializes in module design, state management, multi-cloud deployments, and CI/CD integration. Handles complex infrastructure patterns including multi-environment setups, remote state backends, and secure secrets… - 100terraform-specialist
Expert Terraform/OpenTofu specialist mastering advanced IaC automation, state management, and enterprise infrastructure patterns. Handles complex module design, multi-cloud deployments, GitOps workflows, policy as code, and CI/CD integration. Covers migration strategies,… - 100terraform
Terraform and OpenTofu configuration, modules, testing, state management, and HCL review. Use when working with Terraform, OpenTofu, HCL, tfvars, tftest, state migration, or IaC patterns. - 100terraform
Terraform and OpenTofu configuration, modules, testing, state management, and HCL review. Use for "terraform module", "terraform test", "infrastructure as code", "IaC", "HCL", "tfvars", "terraform plan", "terraform apply", "OpenTofu", "tftest", or multi-environment patterns.