Skip to content

Terraform (infrastructure as code) checklist

Copy this list into a pull request, design review or project kickoff and tick what applies. Rules are grouped by level and sorted by score (criteria). Each links to the file that explains it and cites its sources. Automatable names tools that can check the rule in CI (see the file's "How to enforce" section).

Also apply the general checklist.

This file is generated by python3 scripts/rank.py fix from the guidelines. Don't edit it by hand.

  • TF-1 (9) Store state in a remote backend with locking and encryption at rest, restrict who can read it, and never commit state files. (specific/terraform)
  • TF-2 (8) Give Terraform short-lived credentials, such as OIDC from the CI platform or HCP Terraform dynamic provider credentials, instead of static keys. Never put credentials in provider blocks or variables. (specific/terraform) Automatable: Checkov Terraform policies, Trivy Terraform scanning.
  • TF-4 (8) Split infrastructure into separate root modules, each with its own state, by environment, blast radius, rate of change and team ownership. (specific/terraform)
  • TF-10 (8) Pin versions: set required_version, constrain providers with ~> in root modules but only by minimum in reusable modules, pin module versions, and commit .terraform.lock.hcl. (specific/terraform) Automatable: Checkov Terraform policies, Dependabot for Terraform, TFLint Terraform ruleset.
  • TF-11 (8) Run Terraform from a pipeline: plan every change, save the plan with -out, and apply exactly that plan after review. (specific/terraform)
  • TF-3 (7) Keep secrets out of state where the provider allows it, with ephemeral values and write-only arguments (Terraform 1.10 and 1.11 or later), and protect saved plan files like state. (specific/terraform)
  • TF-5 (7) Give each environment its own directory, with its own backend, that calls shared modules. Don't use CLI workspaces for environments that need separate credentials or access controls. (specific/terraform)
  • TF-6 (7) Rename and move resources with moved blocks, and keep old moved blocks in shared modules. (specific/terraform)
  • TF-7 (6) Keep the module tree flat: compose child modules in the root module and pass their dependencies in as variables. (specific/terraform)
  • TF-8 (6) Write modules that do one thing well at a higher level of abstraction, not thin wrappers around a single resource. (specific/terraform)
  • TF-12 (6) Run terraform fmt -check, terraform validate and TFLint on every change, and test reusable modules with terraform test. (specific/terraform) Automatable: terraform fmt -check.
  • TF-13 (6) Check plans against security and organisation policies as code before applying them. (specific/terraform) Automatable: Checkov Terraform policies, HCP Terraform policy enforcement, Trivy Terraform scanning.

Conditional (1–5)

  • TF-9 (5) Protect costly stateful resources, such as databases and storage, with prevent_destroy, sparingly. (specific/terraform)
  • TF-14 (5) Detect drift on a schedule, for example with terraform plan -detailed-exitcode or HCP Terraform health assessments. (specific/terraform) Automatable: HCP Terraform policy enforcement.