agentleFS
pvnarppvnarp/agent-skills/skills/iac/SKILL.md

iac

Skill1 starsChanged 9 months agoMITView on GitHub

Designs and reviews Infrastructure as Code - Terraform/Pulumi/CloudFormation patterns, state management, module design, change safety, and drift detection. Use when provisioning infrastructure, reviewing IaC changes, or debugging infrastructure issues.

2 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

9 rules. About 0 are common, 8 are distinctive, and 1 is 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.

  • 1

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Everything in code: If it exists in production, it's defined in code.

    line 12
  2. Distinctive:

    Plan before apply: Always review the diff before making changes.

    line 13
  3. Distinctive:

    Inputs are explicit: - no hardcoded values inside modules

    line 112
  4. Distinctive:

    Version your modules: - use git tags or registry versions

    line 116
  5. Very specific:

    Never hardcode secrets in IaC files: Not even in .tfvars.

    line 155
  6. Distinctive:

    When someone makes a manual change that doesn't match the code:

    line 166
  7. Distinctive:

    If there's drift:

    line 172
  8. Distinctive:

    If manual change was correct: update the code to match

    line 174
  9. Distinctive:

    Never apply without a plan review

    line 195

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 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

Infrastructure as Code

IaC makes infrastructure reproducible, reviewable, and version-controlled. It also makes it possible to delete your production database with a typo. Respect the power.

Core Principles

  1. Everything in code. If it exists in production, it's defined in code. No manual console changes.
  2. Plan before apply. Always review the diff before making changes. Always.
  3. Small changes. One concern per PR. Don't refactor modules while adding a new service.
  4. Immutable infrastructure. Replace, don't mutate. New AMI > patch existing server.
  5. Blast radius awareness. Know what a change can destroy before you apply it.

Tool Comparison

FeatureTerraformPulumiCloudFormationCDK
LanguageHCLPython/TS/GoYAML/JSONPython/TS
StateRemote (S3, etc.)Pulumi Cloud / self-managedAWS-managedAWS-managed
Multi-cloudYesYesAWS onlyAWS only
Learning curveLow-mediumLower (real language)MediumMedium
CommunityLargestGrowingAWS-focusedAWS-focused

Project Structure

infrastructure/
├── modules/              # Reusable modules
│   ├── vpc/
│   ├── database/
│   ├── service/
│   └── monitoring/
├── environments/          # Environment-specific config
│   ├── dev/
│   │   ├── main.tf
│   │   ├── variables.tf
│   │   └── terraform.tfvars
│   ├── staging/
│   └── production/
├── global/                # Shared resources (DNS, IAM)
└── README.md

Rules:

  • Separate state per environment (dev state can't affect prod)
  • Modules are reusable (same module, different parameters per env)
  • Environment differences are in variables, not in code duplication

State Management

State is the mapping between your code and real infrastructure. Lose it or corrupt it and you're in trouble.

Remote State (Required for Teams)

# Terraform: S3 + DynamoDB for locking
terraform {
  backend "s3" {
    bucket         = "mycompany-terraform-state"
    key            = "production/main.tfstate"
    region         = "us-east-1"
    dynamodb_table = "terraform-locks"
    encrypt        = true
  }
}

State Rules

  • Never edit state manually (unless you truly understand the consequences)
  • Lock state during operations (prevents concurrent modifications)
  • Encrypt state at rest (it contains secrets and resource details)
  • Separate state per environment (one state file per env)
  • Back up state (enable versioning on the state bucket)

State Operations (Use Rarely, Carefully)

# Import existing resource into state
terraform import aws_s3_bucket.my_bucket my-existing-bucket

# Remove resource from state (without destroying it)
terraform state rm aws_s3_bucket.my_bucket

# Move resource within state (rename without destroy/recreate)
terraform state mv aws_s3_bucket.old_name aws_s3_bucket.new_name

Module Design

Good Module

module "api_service" {
  source = "../modules/service"

  name        = "order-api"
  environment = "production"
  image       = "order-api:v1.2.3"
  cpu         = 512
  memory      = 1024
  port        = 3000
  replicas    = 3

  database_url = module.database.connection_string
  vpc_id       = module.vpc.id
  subnet_ids   = module.vpc.private_subnet_ids
}

Module Principles

  • Inputs are explicit - no hardcoded values inside modules
  • Outputs expose what consumers need - connection strings, IDs, ARNs
  • Defaults are sensible - dev-friendly defaults, override for prod
  • Scope is clear - a module does one thing (a service, a database, a VPC)
  • Version your modules - use git tags or registry versions

Change Safety

The Plan Review

terraform plan -out=tfplan    # Always save the plan

In the plan output, check:

  • + create - new resources (usually safe)
  • ~ update in-place - modify existing (review what's changing)
  • -/+ destroy and recreate - DANGEROUS - resource will be deleted and recreated
  • - destroy - DANGEROUS - resource will be deleted

Dangerous Changes (Require Extra Review)

ChangeRiskMitigation
Rename a resourceDestroy + recreateUse moved block or state mv
Change resource typeDestroy + recreateImport new, remove old from state
Modify immutable fieldsDestroy + recreateCheck if the field triggers replacement
Remove a resourceDeletionVerify it's truly unused
Change database instance typePotential downtimeCheck if it requires restart
Modify security groupsAccess changesReview rules before and after

Protect Critical Resources

resource "aws_rds_instance" "production" {
  # ...
  lifecycle {
    prevent_destroy = true    # Terraform will refuse to destroy this
  }
}

Secrets in IaC

Never hardcode secrets in IaC files. Not even in .tfvars.

ApproachHow
Environment variablesTF_VAR_database_password
Secret manager referencedata.aws_secretsmanager_secret_version
CI/CD secretsInjected during pipeline execution
SOPS / ageEncrypted files in repo, decrypted at apply time

Drift Detection

When someone makes a manual change that doesn't match the code:

terraform plan    # Shows diff between code and reality

If there's drift:

  1. Don't just apply - understand what changed and why
  2. If manual change was correct: update the code to match
  3. If manual change was wrong: apply to restore code's state
  4. Prevent future drift: enforce "no console changes" policy, use CI/CD for all changes

CI/CD for Infrastructure

PR opened:
  → terraform fmt -check (formatting)
  → terraform validate (syntax)
  → terraform plan (show what would change)
  → Post plan output as PR comment

PR merged to main:
  → terraform plan (regenerate)
  → Manual approval gate (for production)
  → terraform apply
  → Verify health checks

Rules:

  • Never apply without a plan review
  • Production requires manual approval
  • Plan output visible in PR (reviewers see what will change)
  • State locking prevents concurrent applies

Reference: reference/iac-patterns.md - tool comparison, state management strategies, module patterns, common resource table, drift remediation, secrets handling, tagging strategy.

Review Checklist

  • Plan reviewed - no unexpected destroys or recreates
  • Secrets not hardcoded (using secret manager or env vars)
  • Critical resources have prevent_destroy
  • State is remote, encrypted, and locked
  • Module inputs are explicit (no hidden assumptions)
  • Environment differences are in variables, not code
  • Naming is consistent and includes environment
  • Tags applied for cost tracking and ownership

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.