Loading...
Loading...
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.
npx skill4agent add iliaal/ai-skills terraform| File | Purpose |
|---|---|
| Terraform + provider version requirements |
| Provider configurations |
| Primary resources and data sources |
| Input variables (alphabetical) |
| Output values (alphabetical) |
| Local values |
web_apiwebAPIweb-apiaws_instance.web_apiaws_instance.web_api_instancethisvpc_cidr_blockcidrcountfor_eachtagsdepends_onlifecycledescriptiontypedefaultvalidationnullabletypedescriptiondescriptionsensitive = true| Type | Scope | Example |
|---|---|---|
| Resource Module | Single logical group | VPC + subnets, SG + rules |
| Infrastructure Module | Collection of resource modules | Networking + compute for one region |
| Composition | Complete infrastructure | Spans regions/accounts |
module-name/
├── main.tf, variables.tf, outputs.tf, versions.tf
├── examples/
│ ├── minimal/
│ └── complete/
└── tests/
└── defaults.tftest.hclexamples/| Scenario | Use |
|---|---|
| Boolean toggle (create or skip) | |
| Named/keyed items that may reorder | |
| Fixed identical replicas | |
for_eachcountcount| Situation | Approach |
|---|---|
| Quick validation | |
| Pre-commit | + |
| Logic validation (1.6+) | Native |
| Cost-free unit tests (1.7+) | Native tests + |
| Real infra validation | Native tests with |
.tftest.hcltests/command = plancommand = applyassert { condition = expr; error_message = "..." }expect_failures = [var.name]mock_provider "aws" { mock_resource "..." { defaults = { ... } } }variables {}runrun.setup.vpc_idparallel = truestate_key = "name"parallel = true*_unit_test.tftest.hcl*_integration_test.tftest.hclmodule {}run-verboseterraform test # all *.tftest.hcl under tests/
terraform test -filter=vpc_unit_test.tftest.hcl # one test FILE (not a run-block name)
terraform test -verbose # show the plan/apply per run block
terraform test -test-directory=path # non-default test dir| Component | Strategy | Example |
|---|---|---|
| Terraform | Pin minor | |
| Providers | Pin major | |
| Modules (prod) | Pin exact | |
| Modules (dev) | Allow patch | |
movedoptional()use_lockfile = truedynamodb_tableuse_lockfile.tfstate.terraform/*.tfplan.terraform.lock.hcldefault_tags0.0.0.0/0terraform fmt -recursiveterraform validate && tflint && trivy config .moved { from = old; to = new }terraform force-unlock <ID>terraform plan -refresh-onlyterraform apply -refresh-onlyterraform apply -replace=ADDRterraform taintimportterraform import ADDR IDlocalstry()depends_onlocals {
vpc_id = try(aws_vpc_ipv4_cidr_block_association.this[0].vpc_id, aws_vpc.this.id, "")
}cidrsubnet(var.vpc_cidr, 8, count.index)provider "aws" { alias = "eu_west_1" }providers = { aws = aws.eu_west_1 }terraform fmt -check && terraform validate && tflint && trivy config .terraform test -filter=<unit-test-file>