1---2name: terraform-123description: Use when the project uses Terraform or OpenTofu for infrastructure-as-code provisioning4---56# Terraform/OpenTofu Best Practices78## Module Composition910- Organize code into reusable modules: `modules/{resource-type}/` with `main.tf`, `variables.tf`, `outputs.tf`11- Use the `module` block to compose infrastructure: pass inputs via variables, expose outputs for downstream use12- Follow the principle of one module per logical resource group (e.g., `vpc`, `database`, `eks-cluster`)13- Version modules with git tags or registry versions: `source = "git::https://...?ref=v1.2.0"`14- Use `locals` for computed values and transformations; avoid complex logic inside resource blocks1516## State Management1718- Store state remotely: use S3+DynamoDB (AWS), Azure Blob (Azure), or GCS (GCP) with locking enabled19- Never commit `.tfstate` to version control -- it contains sensitive outputs20- Use `state encryption` for sensitive deployments; configure in the backend block21- Run `terraform plan` before every apply; review the diff carefully for destructive changes22- Use `terraform import` to bring existing resources under Terraform management without recreation2324## Workspace Strategies2526- Use Terraform workspaces for environment separation (dev/staging/prod) with identical configurations27- Map workspace names to environment-specific variables via `terraform.workspace` in locals28- For large-scale separation, prefer separate state files per environment over workspaces29- Label resources with workspace tags: `Environment = terraform.workspace` for cost tracking3031## Provider Configuration3233- Pin provider versions with `required_providers` block: `version = "~> 4.0"`34- Use `provider` aliases for multi-region or multi-account deployments35- Pass provider credentials via environment variables or IAM roles -- never hardcode in `.tf` files36- Use `dynamic` blocks for repeatable nested configurations: security group rules, IAM policies3738## Testing and Validation3940- Run `terraform validate` and `terraform fmt` in CI before every merge41- Use `tflint` for linting beyond built-in validation: detect unused variables, deprecated syntax42- Write Terratest integration tests for critical infrastructure: `terraform.InitAndApply` + assertions43- Use `check` blocks (Terraform 1.3+) for custom data assertions without external tools44- Implement `terraform plan` as a PR check; post the plan diff as a comment for review4546---47> Source: [calcosmic/Aether](https://github.com/calcosmic/Aether) — distributed by [TomeVault](https://tomevault.io).48<!-- tomevault:4.0:skill_md:2026-05-22 -->
Run npx get-skill add tomevault-io/terraform-12 in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
Use when the project uses Terraform or OpenTofu for infrastructure-as-code provisioning It is listed under DevOps & Infra on SkillMD.
This skill has not completed SkillMD's automated safety review yet. Independent scanners report: SkillSpector: PASS, Skill Scanner: PASS. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
tomevault-io (@tomevault-io) published this skill. Their other Agent Skills are listed on their SkillMD profile.