Skip to navigation

Claude Code Terraform Plans: Review Gates Before Apply

In short: Turn Terraform plans into reviewed evidence with saved plans, JSON checks and explicit approval before apply.

Published 17 min read
On this page

Direct answer

A Terraform plan proves intent, not outcome. The plan command previews the changes Terraform proposes and carries none of them out, which makes a plan the right artifact for review and the wrong artifact to trust as a guarantee. A gate placed before terraform apply works only when three things are true at once: the plan came from a fresh refresh, a human who is not the agent approved that exact saved plan, and the apply references the same plan file rather than a re-run against a changed target. Give Claude Code the read-only side of this loop and keep the apply decision with a named person.

The concrete win is a review that sees a frozen change set instead of a live summary of whatever the provider returned seconds ago. The concrete loss is that review quality drops under time pressure and that a saved plan can contain sensitive values, so the artifact needs protection rather than a commit to the repository. Treat the plan gate as the smallest useful control, then pair it with state access controls so the agent cannot reach the apply path at all.

Why the gate earns its cost

An apply that nobody read is how a routine tag change becomes an accidental database replacement. Agent-generated configuration adds a second failure mode: the suggestion can be fluent, plausible and still wrong about which resource gets destroyed. A plan review catches the destructive intent while it is still text on a screen.

Three costs show up repeatedly without a gate. Reviewers argue from memory about what a change was supposed to do. An apply runs against a target that drifted after the plan was shown, so the executed work differs from the reviewed work. A reviewer sees a clean diff and assumes the environment matched it, which is exactly the gap a disabled refresh leaves behind.

The gate is cheap relative to those outcomes. A read-only plan costs a provider API round trip. A saved plan costs a file and a place to keep it. Neither is close to the cost of restoring a deleted resource group.

What Terraform Plan Actually Proves

The plan reference describes the command as a preview: Terraform determines which actions are necessary to reach the desired state described in configuration and reports them. Official, F001: the plan command alone does not carry the changes out.

A plan proves three things and nothing more. Configuration parsed successfully. The provider returned enough information to compute a diff. The diff at that moment would perform the listed actions if applied to the same target state.

A plan does not prove that the apply succeeds, that the target state is unchanged since the plan ran, or that the resulting infrastructure is safe to operate. The reference itself notes that intervening changes to the target can alter the final effect of an apply. Reviewers who treat “plan passed” as “apply is safe” have skipped the step that actually carries risk.

Plan mode Evidence value Operational risk
terraform plan printed to the terminal Shows the proposed actions for that run Ephemeral; nothing binds the later apply to what was shown
terraform plan -out=tfplan Freezes the change set in an opaque file Cleartext sensitive values; artifact needs protection
terraform plan -refresh=false Fast; shows config intent against stored state Can omit external changes, including drift elsewhere
terraform show -json tfplan Machine-readable actions for scripted checks Still only a proposal; no runtime proof

Read the third row as the common shortcut and the common mistake. A refresh-disabled plan is a fast intent check, not drift evidence.

Saved Plans Versus Speculative Plans

A speculative plan is one that was never saved. It exists in a terminal scrollback and cannot be referenced later. A saved plan, written with -out, is an opaque file that Terraform can apply directly.

Official, F002: the saved plan file can contain configuration and input values in cleartext. The reference warns that these artifacts may include sensitive values. A saved plan is therefore a privileged file, not an ordinary attachment.

That single property drives most of the practical guidance in this post. A plan file that reaches a public pull request has leaked whatever secrets the configuration referenced, even though the apply never ran. Terraform state documentation makes the same class of point about state itself, and the two artifacts tend to be mishandled together. The API key security guide covers the same disclosure risk from the credential side.

Saved plans buy a specific property: the apply can consume exactly the reviewed bytes. Without -out, an approval is a memory, and the apply re-computes the diff against whatever the world looks like at execution time.

bash
terraform plan -out=tfplan.binary
terraform show -json tfplan.binary > tfplan.json
# reviewer inspects tfplan.json, then a human runs the apply
terraform apply tfplan.binary

The JSON side of that sequence is what makes the gate scriptable. A reviewer can diff tfplan.json against policy without re-running the plan.

Reading JSON for Resource Actions

The terraform show -json output exposes each planned resource change with an action field. Classify before you approve.

Resource action Reviewer question Required evidence
create Is this resource expected, and is naming deterministic? Ticket or change request naming the resource
update Which attribute changes, and is it in-place or forced replacement? Attribute-level diff, not a summary
delete Who owns this resource and what breaks when it leaves? Named owner plus a rollback or restore path
replace (delete then create) Is the replacement intentional, and is data preserved? Explicit acknowledgment of data loss
read / no-op Why does a read appear at all? Confirmation that no state mutation is intended

Two attributes deserve special attention. replace hides a delete inside an update-shaped line, which is why attribute-level inspection beats reading the action label. Index and for_each keys that changed can turn an in-place update into a mass delete, and the JSON view is where that shows up before it reaches production.

Script the boring parts. A check that fails when any resource change is delete or replace outside an explicitly approved list catches the highest-risk category without human effort.

Refresh and Drift Caveats

Official, F003: disabling refresh, or using minimal refresh, can omit external changes, including drift in resources that were not selected for change. A faster plan is not a complete view of the environment.

The plan reference describes refresh behavior directly. A default plan reads current remote state first, then computes the diff against it. Turning that read off trades completeness for speed and API quota.

Refresh setting What the plan reflects Known blind spot
Default refresh Current remote state where the provider can see it Provider visibility limits; resources it cannot read
-refresh=false Stored state only External changes since the last refresh are invisible
Minimal refresh Narrowed read set Drift in resources outside the planned change set

Keep refresh-enabled plans as the default evidence for any approval that matters. Use a refresh-disabled plan when the missing drift is understood and written down, not as a routine speedup. State deserves its own triage pass, which the Terraform drift triage guide covers separately, because refresh is also where drift surfaces.

Evidence map showing Terraform plan output feeding a plan gate, then human approval, with drift as a separate input the plan may not fully capture.
Editorial evidence map based on F001 and F003. A plan is a proposal, not proof that the resulting infrastructure is safe. Labels are the post author’s.

Human Approval Gate

An approval gate is a named decision, tied to one saved plan, made by someone who did not generate the configuration. Three properties make it real.

Identity. The approver is a specific person on record, not “the team” and not the agent session.

Binding. The approval names the plan artifact it reviewed, so a later re-plan does not inherit an old approval.

Separation. The identity that approves is not the identity that executes, and neither is the agent. Independent, F033-adjacent: OWASP guidance on secure coding with AI calls for human review of CI/CD changes made by AI coding agents and treats agent output as untrusted input.

The agent sits on the proposal side. Claude Code security documentation describes permission modes, sandboxing and managed settings as safeguards, and none of them constitute a business approval. An agent clicking “approve” on its own apply is not a control; it is the control failing quietly.

Plan result Approval owner Next step
Create-only, low blast radius Service owner Approve and let the execution identity apply
Update touching shared infrastructure Platform owner Review attribute diff, then approve or split
Any delete or replace of stateful resources Service owner plus platform owner Two-person approval before execution
Refresh-disabled plan Reviewer who accepts the blind spot Record the accepted gap, then decide

Record who approved what in a form that survives the session. The SOC 2 change evidence packets guide shows a packet structure that keeps requester, reviewer and approver distinct.

Protecting Plan Files

Plan files leak in three ordinary ways: committed by habit, attached to a public issue, or left in a shared CI artifact directory. Each one publishes values the plan captured in cleartext.

Put plan artifacts outside the repository working tree and add the extension to ignore rules before the first plan runs. Store saved plans in a location with the same access discipline as state, since a plan is a near-state artifact in content. Retain them for the review window and the audit window, then remove them on a schedule.

bash
  # keep plan artifacts out of version control
echo "*.tfplan*" >> .gitignore
echo "tfplan.json" >> .gitignore

The state side of this problem is larger and is covered in Claude Code Terraform State: Locking and Access Controls, which treats state as a privileged dependency with its own identity split.

Recording the Decision

An approval without a record is indistinguishable from an accident after the fact. Keep four fields with every gated change.

Requested by, and the change reason. The plan artifact identifier, so the reviewed bytes are identifiable later. Approver identity and time. The verification result after apply, which is the part teams most often skip.

Field Why it exists Where it lives
Requester and reason Connects the change to an owner Change request
Plan artifact ID Binds approval to reviewed bytes Change record
Approver and timestamp Names the accountable human Change record
Post-apply verification Confirms intended effect Follow-up check

Tool decision events inside Claude Code can record permission outcomes, which supports a decision record but does not assign business accountability. Correlation identifiers help reconstruct an audit trail, a topic the audit evidence integrity guide treats in depth. For accountability across a team, the RACI ownership guide names an accountable human per change class.

Workflow from generating a saved plan through JSON action classification, human approval bound to the plan file, and a guarded apply with verification.
Editorial workflow based on F001 and F002. The apply step is a separate human decision consuming the reviewed plan artifact.

When to Stop the Apply

A gate that never stops anything is decoration. Stop and re-plan when any of these appear.

The target changed after the plan was generated, so the saved plan no longer matches reality. Any delete or replace touches a resource without a named owner and a restore path. A reviewer cannot explain why a resource action appears in the diff. The plan was produced with refresh disabled and the blind spot was never written down. The approver is also the identity that generated the configuration.

Signal Why it blocks Resolution
Target drifted since the plan Reviewed diff no longer matches reality Re-plan, then re-approve
Unowned delete or replace Data loss with no restore path Name an owner or remove the action
Unexplained action Reviewer cannot vouch for the change Investigate before approving
Accepted refresh gap unrecorded Drift outside the change set is unknown Record the gap or refresh and re-plan
Agent self-approval Control separation failed Restart the gate with a human approver

The stop list is intentionally short so it gets used. A long list becomes a checklist people skim.

Control checklist

Run this before any gated apply. Each row is a pass condition, not a suggestion.

Check Pass condition If it fails
Plan source Plan ran with default refresh unless a gap was accepted Re-plan with refresh enabled
Saved artifact A plan file exists and is referenced by the approval Re-run plan with -out
Action classification Every create, update, delete and replace reviewed at attribute level Inspect terraform show -json output
Ownership Every touched resource has a named owner Block until owners are named
Approver separation Approver is not the generating identity and not the agent Find a separate approver
Plan file protection Artifacts excluded from version control Fix ignore rules before proceeding
Apply binding Apply consumes the reviewed plan file Re-plan and re-approve
Tradeoff between a frozen saved plan that binds approval to reviewed bytes and the sensitive-value exposure that requires artifact protection.
Editorial tradeoff diagram based on F002. Saving the plan makes review binding; the trade is handling a file that may contain cleartext sensitive values.

Working with Claude Code on a plan

Give the agent three inputs before it plans: the target workspace, the commands it may run, and the definition of a complete proposal. Ask for the saved plan and its JSON render, and ask it to list resource actions by category rather than summarize.

Reviewing the proposal is the reviewer’s job. The agent can read configuration and run read-only commands, but deciding whether a delete is acceptable is a business decision. The security documentation covers the safeguards that keep the agent on the proposal side, and the OWASP AI cheat sheet frames why agent output stays untrusted even when it looks correct.

For teams building this into a wider system, the Claude Code Risk-Tiered Infrastructure Approvals guide classifies changes by blast radius and reversibility, and the Claude Code Policy as Code: Audit Before Deny guide adds automated guardrails that report before they block.

Control checklist covering refresh source, saved artifact, action classification, ownership, approver separation, plan file protection and apply binding.
Editorial control checklist derived from F001 through F003. Passing the checklist shows the gate was applied honestly; it does not certify the resulting infrastructure.

The concrete win, loss, and implication

The concrete win is a review that binds. An approver signs off on one saved plan, and the apply consumes those bytes, so the reviewed change and the executed change are the same object instead of two runs hoping to match.

The concrete loss is artifact risk plus review fatigue. A saved plan can carry sensitive values in cleartext, so it needs storage discipline, and a gate applied to every trivial change trains reviewers to approve without reading.

The practical implication is separation of duties. Teams that keep the agent on proposals and a named human on approval catch destructive intent while it is still text. Teams that let the agent approve its own apply have a gate in name only, and they usually find out from an incident rather than a review.

Verdict that a plan gate works only when a human approver is bound to the saved plan and the apply consumes that same artifact.
Editorial verdict based on F001 and F002. Review the frozen change set and keep the apply decision with a human who did not generate the configuration.

Data gap and future update

The Terraform plan and apply reference pages support the refresh and saved-plan claims in F001 through F003. Backend-specific behavior, including how a given remote backend exposes saved plans and locking, is left to the backend documentation and was not verified in the research pass behind this post.

No measurement of review time, apply failure rate or incident reduction is reported here, because none was collected. A future update quantifying how a saved-plan gate affects caught-before-apply error rates would need a fixed repository history and a defined review population. No such data exists in the public sources used.

Provider-specific resource types, data sources and sensitive-value handling also vary. This post describes the plan mechanism generally and does not generalize any provider’s behavior.

One AI API Key option for OpenAI-format agents

Claude Code uses an Anthropic-format route, so the One AI free model IDs are not a Claude Code model source. The packet records Claude IDs as unavailable on 2026-11-27.

OpenAI-format agents have a separate route: One AI API Key provides https://api.oneaiapikey.com/v1, one key, and 46 live free IDs. That is a different client and request format, not a workaround for Claude Code authentication. See the free model list for eligibility notes, or the quickstart for the request shape. The cost calculator helps compare hosted options before you commit.

FAQ

Does a clean plan mean the apply is safe?

No. A plan proves the diff was computed, not that the apply succeeds or that the target state still matches. Intervening changes to the target can alter the final effect, which is why the apply should consume the reviewed plan file rather than re-run the diff.

Why save a plan instead of just re-running it at apply time?

Saving freezes the change set that was reviewed. Re-running at apply time computes a fresh diff against current remote state, so the executed work can differ from the reviewed work. A saved plan makes approval binding.

Can Claude Code approve its own apply?

It should not, and treating it as an approver is the control failing. Claude Code safeguards such as permission modes and sandboxing govern what the agent can do technically; they do not provide business approval. A named human outside the generation path holds the apply decision.

What is wrong with a refresh-disabled plan?

It can omit external changes, including drift in resources not selected for change. Use it when the missing drift is understood and recorded. As routine practice it hides more than it shows.

Where should saved plan files live?

Outside version control, in storage with the same access discipline as state, since the file can contain sensitive values in cleartext. Retain them for review and audit windows, then remove on a schedule.

The plan gate is one control in a wider set. On the state side, Terraform state locking and access controls covers backend locking and the identity split between planning and applying. When a plan reveals differences nobody requested, the Terraform drift triage guide covers what to do next.

Three Kubernetes posts extend the same review discipline to cluster writes. Field ownership before an agent updates shared objects is covered by server-side apply ownership checks. The permissions you grant before any of this runs are covered by Kubernetes RBAC least privilege reviews. Traffic policy and CNI enforcement are covered by NetworkPolicy blast radius reviews.

Governance inputs around the gate appear in cloud IAM permission boundaries and Pod Security admission gate reviews. Change-record structure is covered by SOC 2 change evidence packets and access recertification for agent identities. Approval and ownership models appear in risk-tiered infrastructure approvals, RACI ownership for infrastructure changes, and change freeze emergency rules.

More platform reading

Agent boundaries and evidence quality sit behind every gate in this post. Modeling the assets and credentials an agent can reach is covered by infrastructure threat model boundaries. Judging telemetry before using it as evidence is covered by audit evidence integrity checks. Reviewing the deployed configuration rather than product claims is covered by the vendor security review checklist.

More Claude Code troubleshooting

Sources

More in Blog

Try it

One API key for GPT, Grok, DeepSeek, Kimi, GLM, MiniMax, Qwen, Step, Beam, Nemotron, ERNIE, Hunyuan, Gemma, Laguna, LFM, LongCat, Llama, Solar, Jais, Mistral, K2 and Roleplay.

One AI API Key speaks the OpenAI and Anthropic formats, so you change the base URL and the key, not your code. Credit packs start at $10, and every model has a published per-token rate.

New accounts$10 credit on sign-up
Claim $10 credit →