Infrastructure as Code Code Review Checklist: Terraform Modules, State, Security, and Testing
Infrastructure as CodeTerraformOpenTofuCode ReviewPlatform Engineering

Infrastructure as Code Code Review Checklist: Terraform Modules, State, Security, and Testing

MMidways Cloud Editorial Team
2026-11-13
7 min read

A reusable Terraform and OpenTofu review checklist covering plans, modules, state, security, testing, drift, and rollback.

Use this infrastructure as code code review checklist to evaluate Terraform or OpenTofu changes before they reach a shared environment. It covers plan impact, module design, state, security, testing, dependencies, drift, and rollback so reviewers can make approval decisions based on risk rather than formatting preferences.

Overview

An infrastructure pull request is more than a set of configuration edits. It is a proposed change to networks, identities, data stores, compute capacity, policies, and the operational assumptions around them. A useful review therefore asks two questions: Does this configuration express the intended design? and What could happen when the tool applies it?

The checklist below is designed for Terraform and compatible workflows, including teams evaluating Terraform versus OpenTofu. Adapt the required checks to the sensitivity of the target environment. A development workspace may only need a plan review and basic validation, while a production change should also have explicit ownership, policy checks, backup considerations, monitoring, and a tested recovery path.

Reviewers should inspect both the code and the generated plan. A clean-looking module can still produce an unexpected replacement, broad permission change, public endpoint, or state operation. Conversely, a large plan may be intentional when a resource is being migrated. The goal is to understand the resulting infrastructure, not simply approve a diff.

Checklist by scenario

For every infrastructure pull request

  • Intent: The pull request explains the problem, affected environments, expected resources, and reason for the change.
  • Scope: The changed files match the stated purpose. Unrelated formatting, provider upgrades, and refactoring are separated or clearly called out.
  • Plan: A plan was generated from the intended workspace, variable set, backend, and commit. Review the complete output, not only the summary.
  • Actions: Identify additions, updates, replacements, and deletions. Treat replacement and destruction as high-risk actions until their necessity is confirmed.
  • Dependencies: Check provider, module, and lock-file changes. Confirm that version constraints remain deliberate and that dependency changes are tested rather than incidental.
  • Validation: Run formatting, initialization, validation, linting, security checks, and relevant automated tests in the same way the CI/CD workflow will run them.
  • Ownership: The owning team, approver, and operational contact are clear, especially for shared networking, identity, DNS, data, and platform resources.

For a new or changed module

  • Review the module interface: input names, types, descriptions, defaults, nullability, validation rules, and sensitive flags.
  • Confirm that outputs expose useful identifiers without leaking credentials, tokens, private keys, or other sensitive values.
  • Check whether defaults are safe. A convenient default should not silently create a public resource, overly broad access, unencrypted storage, or an expensive high-capacity configuration.
  • Look for hidden coupling. A module should make provider aliases, regions, subscriptions, projects, naming rules, and dependencies understandable to its caller.
  • Check resource naming, tags or labels, ownership metadata, and lifecycle behavior against the platform's conventions.
  • Verify that examples and tests cover the normal path, an invalid input, and any important optional feature.

For state, imports, and migrations

  • Confirm that the backend and workspace are correct and that state locking or equivalent concurrency protection is active where supported.
  • Ask whether the change alters resource addresses. Renaming a resource or moving it into a module may require an explicit state move or import plan; otherwise the tool may propose destroy-and-create behavior.
  • Review import blocks, state move declarations, or migration commands for exact addresses and identities.
  • Do not place state files, backend credentials, or generated plans in the repository unless the team has deliberately designed a secure, controlled process for doing so.
  • Check whether a state migration has a backup, an owner, and a recovery procedure. State operations deserve the same care as application database migrations.

For security-sensitive changes

  • Trace every new permission to a specific workload or operator need. Prefer narrowly scoped actions and resources over broad administrative roles.
  • Review network exposure, ingress sources, egress destinations, security groups, firewall rules, load balancer listeners, and private connectivity.
  • Confirm that secrets are referenced through an approved secret-management path rather than hard-coded in variables, locals, examples, or command output.
  • Check encryption settings, key selection, rotation assumptions, audit logging, and recovery access for data-bearing resources.
  • Ensure sensitive values are marked appropriately, while remembering that a sensitive flag can hide output without removing the value from state or the remote system.
  • Run policy-as-code or static security checks, then investigate exceptions instead of treating them as automatic approval blockers or automatic false positives.

For production, data, or destructive changes

  • Identify whether the change can interrupt service, recreate an instance, alter routing, change capacity, or affect existing data.
  • Check backup coverage, restore evidence, retention assumptions, and the order of operations. A backup that cannot be restored is not a complete recovery plan.
  • Review timeouts, health checks, dependencies, and readiness conditions. The apply should not declare success before the service is usable.
  • Define rollback realistically. Some infrastructure changes can be reverted through code; data migrations, irreversible deletes, and external side effects may require a separate recovery procedure.
  • Confirm post-apply verification, alerts, dashboards, and an accountable person watching the change.

What to double-check before approval

Review areaQuestions to askEvidence to request
Plan impactAre any resources replaced or destroyed? Is the action count consistent with the request?Plan output from the correct environment and variables
Module contractAre inputs constrained and outputs intentional? Could a default create an unsafe result?Variable definitions, examples, tests, and documentation
StateWill an address change, import, or backend change cause unexpected recreation or concurrency risk?State-move or import details and migration steps
SecurityDoes the change expand access or exposure? Are secrets absent from code and logs?Policy results, permission diff, network diff, and secret references
ReliabilityWhat happens during failure, timeout, partial apply, or provider error?Timeouts, dependencies, health checks, backup and recovery notes
OperationsWho owns the resource, monitors it, and responds if it behaves differently?Tags, runbook, alerts, dashboard, and handoff details

Use a layered review rather than relying on one command. A typical baseline may include formatting and validation, followed by a plan and automated tests:

terraform fmt -check -recursive
terraform init -backend=false
terraform validate
terraform plan -out=tfplan

For OpenTofu, use the equivalent commands in the toolchain selected by the repository. The exact command set is less important than consistency: the local review, pull request checks, and deployment runner should agree on versions, backends, variables, and policy enforcement. Never treat a local plan as proof that a production apply is safe if the local environment does not reproduce the production inputs.

For Kubernetes-backed platforms, infrastructure review may connect directly to workload behavior. A network, identity, cluster, or storage change can alter deployments and service availability. Pair this checklist with a Kubernetes deployment manifest review checklist when the pull request changes both platform infrastructure and workloads. If the change is part of a cluster upgrade, use the Kubernetes upgrade runbook to review compatibility and rollback steps.

Common mistakes

Approving the code without reading the plan

Configuration can look reasonable while a provider interprets a small argument change as replacement. Review the concrete actions and investigate every deletion, replacement, and unexpected count change.

Using broad defaults for convenience

Defaults such as unrestricted CIDR ranges, wildcard permissions, public access, or large capacity settings reduce friction during development but create review debt. Require callers to make consequential choices explicit, or provide a constrained default with validation.

Confusing sensitive output with secret protection

Marking a value sensitive can prevent casual display, but it does not automatically remove the value from state or prevent downstream exposure. Use approved secret storage, protect state access, and avoid passing secrets through unnecessary outputs.

Combining unrelated changes

A provider upgrade, module refactor, resource rename, and production network change in one pull request make plan interpretation difficult. Smaller changes improve review quality and make rollback decisions clearer.

Assuming rollback means reverting the commit

Reverting code may not restore deleted data, external integrations, rotated credentials, or a previously migrated resource address. Document the recovery path before approval, particularly for state and data changes.

Ignoring drift

A plan may include changes caused by manual edits or changes made by another system. Decide whether to reconcile the drift, preserve it intentionally, or adjust ownership boundaries. Applying without understanding drift can overwrite an emergency fix or mask a governance problem.

For recurring operational checks, the CI/CD pipeline maintenance playbook can complement this review process. If an infrastructure change contributes to an incident, preserve the timeline and follow-up actions with a blameless incident postmortem template.

When to revisit

Use this infrastructure as code code review checklist for every pull request, but revisit the checklist itself when the underlying delivery system changes. Schedule a focused review before seasonal planning cycles, major platform migrations, or periods when more teams will consume shared modules.

Update the checklist when the repository changes Terraform or OpenTofu versions, provider versions, module sources, state backends, policy rules, CI/CD runners, or secret-management integrations. Also revisit it after an incident, an unexpected replacement, a state migration, or a security finding. These events often reveal a missing question rather than an isolated reviewer error.

To put the checklist into practice, make the following actions part of the pull request template:

  1. State the intended infrastructure outcome and affected environments.
  2. Attach or link the plan generated from the approved workflow.
  3. Call out replacements, deletions, imports, state moves, permission changes, and public exposure.
  4. Record validation, policy, security, and test results.
  5. Document backup, rollback, monitoring, and post-apply verification for consequential changes.
  6. Assign an owner who can answer operational questions after approval.

Reviewers do not need to treat every infrastructure change as a production emergency. They do need a repeatable way to distinguish routine edits from changes that can affect availability, security, cost, or recoverability. A consistent review process gives platform teams that signal while keeping infrastructure delivery understandable and controlled.

Related Topics

#Infrastructure as Code#Terraform#OpenTofu#Code Review#Platform Engineering
M

Midways Cloud Editorial Team

DevOps and Platform Engineering Editors

Senior editor and content strategist. Writing about technology, design, and the future of digital media. Follow along for deep dives into the industry's moving parts.