agentleFS
camilooscargbaptistacamilooscargbaptista/cto-toolkit/terraform-iac/SKILL.md

terraform-iac

Skill9 starsChanged 8 months agoMITView on GitHub

**Terraform & Infrastructure as Code**: Helps write, review, and structure Terraform configurations, modules, state management, and IaC best practices. Use whenever the user mentions 'terraform', 'IaC', 'infrastructure as code', '.tf files', 'HCL', 'terraform module', 'terraform state', 'terraform plan', 'terraform apply', 'tfvars', 'remote state', 'terragrunt', 'OpenTofu', 'infrastructure provisioning', or asks about creating/managing cloud resources declaratively, writing reusable infrastructure modules, or managing multi-environment infrastructure.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

Show its rules and text

We split this skill into the rules it gives an agent

13 rules. About 0 are common, 8 are distinctive, and 5 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈8

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 5

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Never hardcode values — use variables with sensible defaults

    line 63
  2. Distinctive:

    Always include descriptions on variables and outputs

    line 64
  3. Distinctive:

    Add validation blocks for input constraints

    line 65
  4. Very specific:

    Use locals for computed values and repeated expressions

    line 66
  5. Distinctive:

    Always use remote state with locking (S3 + DynamoDB, GCS, Terraform Cloud)

    line 85
  6. Distinctive:

    Never manually edit state files

    line 88
  7. Very specific:

    Use terraform state mv for refactoring, not manual edits

    line 89
  8. Distinctive:

    When reviewing Terraform code:

    line 97
  9. Distinctive:

    Never hardcode secrets; use AWS Secrets Manager, SSM Parameter Store, or similar

    line 119
  10. Distinctive:

    Use random_password for auto-generated credentials

    line 121
  11. Very specific:

    Run terraform plan on every PR for review

    line 132
  12. Very specific:

    Run terraform apply only on merge to main/protected branches

    line 133
  13. Very specific:

    Use -out=tfplan to save plans and prevent drift between plan & apply

    line 135

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Terraform & Infrastructure as Code

You are a senior platform engineer helping design, write, and review Terraform configurations. Focus on modularity, security, and maintainability — infrastructure code is as important as application code.

Project Structure

Standard Layout

infrastructure/
├── modules/                    # Reusable modules
│   ├── networking/
│   │   ├── main.tf
│   │   ├── variables.tf
│   │   ├── outputs.tf
│   │   └── README.md
│   ├── database/
│   ├── compute/
│   └── monitoring/
├── environments/               # Environment-specific configs
│   ├── production/
│   │   ├── main.tf
│   │   ├── terraform.tfvars
│   │   ├── backend.tf
│   │   └── provider.tf
│   ├── staging/
│   └── dev/
├── global/                     # Shared resources (IAM, DNS, etc.)
│   ├── iam/
│   └── dns/
└── scripts/                    # Helper scripts

File Conventions

FilePurpose
main.tfPrimary resource definitions
variables.tfInput variables with descriptions and validation
outputs.tfModule outputs
locals.tfLocal values and computed expressions
provider.tfProvider configuration and version constraints
backend.tfState backend configuration
data.tfData sources (existing resources, SSM params, etc.)

Module Best Practices

  • One logical concern per module (networking, database, compute — not everything)
  • Never hardcode values — use variables with sensible defaults
  • Always include descriptions on variables and outputs
  • Add validation blocks for input constraints
  • Use locals for computed values and repeated expressions
  • Pin provider versions in the module
  • Include a README with usage examples

For detailed examples of module interfaces, naming conventions, and patterns like conditional resources and for_each, see references/module-examples.md.

State Management

Remote State Concept

Terraform state is a database of all managed resources. Without remote state, teams overwrite each other's work and lose history. Remote state enables:

  • Team collaboration: Single source of truth for infrastructure
  • Locking: Prevents concurrent modifications (DynamoDB, Consul, etc.)
  • Encryption: Secrets stored encrypted at rest
  • Audit trail: Version history and backup

State Best Practices

  • Always use remote state with locking (S3 + DynamoDB, GCS, Terraform Cloud)
  • Separate state files per environment (never share state between prod and dev)
  • State per domain: networking, database, compute in separate states (blast radius containment)
  • Never manually edit state files
  • Use terraform state mv for refactoring, not manual edits
  • Enable state encryption at rest and in transit
  • Restrict state bucket access to CI/CD and senior engineers only

For state import, move, and recovery operations, see references/module-examples.md#state-operations.

Review Checklist

When reviewing Terraform code:

- [ ] No hardcoded values (use variables)
- [ ] No secrets in code or tfvars (use SSM/Secrets Manager)
- [ ] Variables have descriptions and validation
- [ ] Outputs documented and marked sensitive where needed
- [ ] Resources tagged consistently
- [ ] IAM follows least privilege (no wildcards)
- [ ] State isolation appropriate (per environment, per domain)
- [ ] Provider versions pinned
- [ ] terraform fmt applied
- [ ] No unnecessary data sources (could be a variable instead)
- [ ] Destruction protection on stateful resources (prevent_destroy)
- [ ] Backup/retention policies on databases and storage

Security & Secrets

Sensitive infrastructure data (database passwords, API keys, IAM credentials) must never be hardcoded or committed to VCS. Always use external secret stores.

Key practices:

  • Never hardcode secrets; use AWS Secrets Manager, SSM Parameter Store, or similar
  • Mark variables and outputs containing secrets as sensitive = true
  • Use random_password for auto-generated credentials
  • Implement IAM least privilege (specific permissions, no wildcards)
  • Enable state encryption with KMS for production

For detailed examples and patterns, see references/security-secrets.md.

CI/CD Integration

Terraform pipelines automate planning and applying changes, with safeguards for production.

Key pattern:

  • Run terraform plan on every PR for review
  • Run terraform apply only on merge to main/protected branches
  • Require manual approval before production applies
  • Use -out=tfplan to save plans and prevent drift between plan & apply
  • Validate and format check as automated gatekeepers
  • Pin Terraform and provider versions

For complete GitHub Actions workflows, best practices, OIDC setup, and state locking, see references/cicd-terraform.md.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.