agentleFS
benjaminwesternbenjaminwestern/google-engineer-skills/skills/terraform/SKILL.md

terraform

Skill5 starsChanged 8 months agoMITView on GitHub

MUST USE when creating, reviewing, testing, or refactoring Terraform code. Covers modules, providers, resources, variables, CI/CD workflows, policy and validation patterns, and infrastructure-as-code design decisions. Do NOT use for imperative cloud CLI tasks or non-Terraform deployment tooling unless the task explicitly requires Terraform.

23 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use ansible, kubernetes and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • julweberSkill

    ansible

    Ansible automation reference for playbooks, roles, inventory, variables, and modules. Includes Proxmox VE and Docker integration via community.general and community.docker collections. Use when writing playbooks, troubleshooting Ansible runs, or designing automation workflows. Triggers: ansible, playbook, inventory, role, task, handler, vars, jinja2, galaxy, proxmox_kvm, proxmox_lxc, docker_container, docker_compose.

    Also in 4 projects that use this

  • mjunaidcaSkill

    kubernetes

    Production-grade Kubernetes manifests and debugging for containerized applications. This skill should be used when users ask to deploy to Kubernetes, create K8s manifests, containerize for K8s, set up Deployments/Services/Jobs/StatefulSets/CronJobs, create namespaces with resource quotas, set up multi-team isolation, configure ResourceQuota/ LimitRange, secure with RBAC (ServiceAccount, Role, RoleBinding), configure init containers (model download, db wait, migrations), set up sidecars (logging, metrics), or debug pods (CrashLoopBackOff, logs, exec, describe, events). Auto-detects from Dockerfile/code, generates hardened manifests with educational comments. CKAD-aligned.

    Also in 5 projects that use this

  • thechandanbhagatSkill

    sql

    Write SQL queries, optimize database performance, design schemas, and debug SQL issues. Use for database operations, query optimization, and schema design.

    Also in 3 projects that use this

  • MicrosoftSkill

    github-actions

    Use when creating, editing, reviewing, or troubleshooting GitHub Actions workflows in Scope.

    Also in 5 projects that use this

  • VercelSkill

    react

    React renderer for json-render that turns JSON specs into React components. Use when working with @json-render/react, building React UIs from JSON, creating component catalogs, or rendering AI-generated specs.

    Also in 5 projects that use this

  • garri333Skill

    codex-cli

    OpenAI Codex CLI mastery skill for installation, authentication, terminal commands, code generation from natural language, file editing, project scaffolding, and IDE integrations. Covers GPT-5.2 Instant/Thinking tiers and shell/container execution modes.

    Also in 3 projects that use this

The file

We split this skill into the rules it gives an agent

3 rules. 0 are common, 3 are distinctive, and 0 are very specific to this project.

  • 0

    Common

    Most of the 21 edited versions we read keep these.

  • 3

    Distinctive

    This author's own choices. Worth a look.

  • 0

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Every Terraform root module must have:

    line 39
  2. Distinctive:

    When to use factory vs traditional modules

    line 290
  3. Distinctive:

    When NOT to use factory pattern

    line 297

“Common” is measured: kept by at least 6 in 10 of the 21 edited versions of this file we could read. “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 Skill

Comprehensive Terraform guidance covering modules, testing, CI/CD, and production patterns. Combines best practices from terraform-best-practices.com and Cloud Foundation Fabric.


The Seven Mantras

These principles guide all Terraform work:

  1. Always Have versions.tf — Every root module must define providers, versions, and configuration. Never leave provider config implicit.
  2. Always Have backend.tf — Even if empty initially, you'll need remote state (GCS for GCP).
  3. Always Have locals.tf — Centralize all local values, don't scatter them across files.
  4. Vertical Files by Domain — Organize by workload (webserver.tf, salesforce-etl.tf), not by resource type (iam.tf, compute.tf).
  5. Variables with Sane Defaults — Provide sensible defaults and example tfvars files.
  6. YAML Factories for Heavy Reuse — Enable non-Terraform users via YAML configs + factory patterns.
  7. Maximize Autonomy — App repos own their resources, foundations repos own shared infrastructure. Avoid cross-repo dependencies.

Core Principles

1. Required Files

Every Terraform root module must have:

FilePurpose
versions.tfProvider versions and configuration
backend.tfRemote state (even if empty initially)
locals.tfCentralized local values
variables.tfInput variables (when needed)

2. Vertical File Organization

Organize by domain/workload, not by resource type:

# GOOD - Files by domain:
├── networking.tf      # VPC, subnets, routes, NAT
├── webserver.tf       # MIG, template, LB, service account
├── salesforce-etl.tf  # SA, secrets, Cloud Function, BigQuery
└── database.tf        # Cloud SQL, IAM, backups

# BAD - Files by resource type:
├── iam.tf            # All IAM mixed together
├── compute.tf        # All compute mixed together
└── storage.tf        # All storage mixed together

3. Naming Conventions

TypePatternExample
ResourcesDescriptive, contextualweb_server, application_logs
SingletonsUse thisgoogle_compute_network.this
VariablesContext-specificvpc_cidr_block, database_instance_class
Outputs{name}_{type}_{attribute}firewall_rule_id, subnet_ids

4. Module Boundaries

TypeScopeExample
Resource ModuleSingle logical groupVPC + subnets
Infrastructure ModuleCollection of resourcesComplete networking stack
CompositionEnvironment-specificProduction environment
RepositoryOwns its resourcesApp repo = app resources only

Quick Decision Reference

Count vs For_Each

Do resources need meaningful identifiers?
│
├─ YES → for_each (with set or map)
│
└─ NO → Can items change position?
    ├─ YES → for_each (prevents cascade)
    └─ NO → count (simpler)

See code-patterns.md for migration patterns and detailed examples.

Testing Approach

What do you need to test?
│
├─ Syntax/format? → terraform validate + fmt
├─ Security? → trivy + checkov
├─ Simple logic (1.6+)? → Native tests
└─ Complex integration? → Terratest

See testing-frameworks.md for implementation details.

Authentication (GCP)

Always use OIDC. Never use service account keys.

MethodSecurityUse Case
OIDC✅ No long-lived credentialsCI/CD (GitHub Actions)
ADC✅ User credentialsLocal development
Impersonation✅ Service account delegationAutomation
Keys❌ Long-lived riskNever use

See security-compliance.md for OIDC setup and security patterns.


Modern Features (Quick Reference)

FeatureVersionWhen to Use
try()0.13+Safe fallbacks (always use)
optional()1.3+Optional object attributes
moved blocks1.1+Refactor without recreation
Native tests1.6+Unit testing in HCL
Mock providers1.7+Cost-free testing
Write-only args1.11+Secrets (never in state)

Essential Commands

# Static analysis (always free)
terraform fmt -recursive -check
terraform validate
tflint
trivy config .
checkov -d .

# Testing (1.6+)
terraform test

# Plan and apply
terraform plan -out=tfplan
terraform apply -auto-approve tfplan

# State management
terraform state list
terraform show

See quick-reference.md for full cheat sheet.


Security Checklist

  • Authentication: Using OIDC (not keys)
  • Secrets: In Secret Manager (not state/variables)
  • Network: Custom VPC (not default)
  • Firewall: Least privilege (not 0.0.0.0/0)
  • State: Encrypted, versioned, restricted access
  • Scanning: Trivy/Checkov in CI/CD

See security-compliance.md for detailed patterns.


Module Checklist

  • versions.tf with provider constraints
  • backend.tf for remote state
  • variables.tf with descriptions and validation
  • outputs.tf with descriptions
  • examples/ directory (simple and complete)
  • Tests (native 1.6+ or Terratest)
  • Pre-commit hooks configured
  • Documentation in README.md

See module-patterns.md for details.


CI/CD Essentials

Standard Pipeline

validate → plan → apply

Key Decisions

DecisionRecommendation
AuthenticationOIDC (never keys)
Apply triggerPush for dev/staging, approval for prod
WorkspacesSeparate files per environment
Security scanTrivy + Checkov in CI

See ci-cd-workflows.md for templates.


Reference Documentation

code-patterns.md

When to use: Writing or refactoring Terraform code

Covers:

  • Count vs for_each decision guide and migration patterns
  • Block ordering rules (resources, variables)
  • Modern features decision guide (try, optional, moved, write-only)
  • Version constraints and update strategy
  • Secrets management patterns
  • Refactoring from legacy (0.12/0.13) to modern syntax

quick-reference.md

When to use: Need quick lookup or troubleshooting

Covers:

  • Command cheat sheet (format, validate, test, plan)
  • Decision flowcharts (testing, module workflow, refactoring)
  • Version-specific guidance (1.0-1.5, 1.6+, 1.7+)
  • Troubleshooting common issues
  • Version constraint syntax reference

module-patterns.md

When to use: Creating or restructuring modules

Covers:

  • Module type decision tree (Resource → Infrastructure → Composition)
  • Architecture decisions (scope size, module connections)
  • File organization standards
  • Parameterization vs hardcoding
  • Root module vs reusable module boundaries
  • Naming decisions (variables, outputs)
  • Anti-patterns to avoid (god modules, environment sprawl)

testing-frameworks.md

When to use: Setting up or choosing testing approach

Covers:

  • Testing decision flowchart
  • Native tests vs Terratest comparison
  • Critical plan vs apply decision
  • Working with set-type blocks
  • Mocking decisions
  • Terratest patterns and cost management
  • Testing checklist

ci-cd-workflows.md

When to use: Setting up CI/CD pipelines

Covers:

  • Standard validate → plan → apply pipeline
  • OIDC authentication patterns
  • Apply strategy options (push, approval, comment-triggered)
  • Environment organization (separate vs reusable workflows)
  • Essential security checks in CI
  • Atlantis integration decision guide

security-compliance.md

When to use: Security review or compliance setup

Covers:

  • OIDC vs service account key decision
  • Secrets management (what's safe vs unsafe)
  • Network architecture decisions
  • Firewall rule best practices
  • State security requirements
  • Compliance testing tools (trivy, checkov, terraform-compliance, OPA)

factory-patterns.md

When to use: Building scalable, self-service infrastructure

Covers:

  • When to use factory vs traditional modules
  • Configuration format decisions (YAML vs JSON)
  • Discovery methods (single file vs auto-discovery)
  • Default strategy patterns
  • Factory patterns by use case (Project, Subnet, Service Account)
  • Conditional resource creation
  • Lifecycle hooks
  • When NOT to use factory pattern

Based on:

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.