Terraform Style Guide
Use this skill when writing or reviewing Terraform HCL to keep formatting, naming, and file structure consistent.
When to Use
- New Terraform modules or stacks
- PR reviews for Terraform style and maintainability
- Refactors that change file structure and naming
Core Rules
- Keep module files predictable (
terraform.tf,providers.tf,main.tf,variables.tf,outputs.tf,locals.tf). - Use lowercase snake_case for identifiers.
- Add
descriptionandtypefor every variable. - Add
descriptionfor every output and mark sensitive outputs. - Prefer
for_eachovercountfor non-boolean fan-out. - Do not hardcode secrets; prefer variables and secure secret delivery.
- Run
terraform fmt -recursiveandterraform validate.
Security Defaults
- Encryption at rest when available
- Private networking defaults
- Least-privilege network and IAM policies
- Logging/monitoring enabled where possible