Index
Feed
Filed by sixline · Jul 25, 2026
✓ What worked
PreToolUse hook blocks any Bash command matching /terraform (apply|destroy|import|state rm)/. The agent produces plans and a human runs the apply after reading them. This is the only line that's held under pressure, and honestly it should be the default for any agent with cloud creds.
sixline · 1w ago
A make target owns plan/apply: `make plan` hashes the .tf tree into the plan filename; `make apply` refuses if the current hash doesn't match. Agent can only apply a plan generated from the code as it currently exists. Allows autonomy in dev workspaces with the stale-plan hole closed.
rowanp · 1w ago
✕ What did not work
State locking does nothing here — the state hadn't changed, the code had. Terraform validated the plan against state, found it consistent, and destroyed the database exactly as instructed. The safety mechanism checks the wrong thing for this failure.
quinnfields · 1w ago
| Agent | Version | Model | OS | Framework | Outcome | × |
|---|---|---|---|---|---|---|
| Claude Code | 2.4.0 | Claude Opus 5 | Ubuntu 24.04 | Terraform | Reproduced | 5 |
| Codex | 0.45.1 | GPT-5.5 Codex | Ubuntu 24.04 | Terraform | Reproduced | 3 |
Sign in to add your report — every count here is backed by a named account.
Related records
Strong evidence gets promoted into the record above.
Sharing the guts of the hash-gated wrapper since a few people asked:
PLANHASH := $(shell find . -name '*.tf' -not -path './.terraform/*' | sort | xargs sha256sum | sha256sum | cut -c1-12)
plan:
terraform plan -out=tfplan.$(PLANHASH)
apply:
@test -f tfplan.$(PLANHASH) || { echo "ERROR: no plan for current code (hash $(PLANHASH)). Run make plan."; exit 1; }
terraform apply tfplan.$(PLANHASH)The error message is agent-readable on purpose — when it hits the gate it re-plans instead of arguing.
Adopted this in dev workspaces alongside the apply-deny in staging/prod. Belt and suspenders, different trust levels per workspace. Marking as the verified mitigation for autonomy-preserving setups.
Question for the thread: has anyone seen an agent run terraform state rm or state mv on its own initiative during error recovery? That's the next escalation of this failure class and I'd like a repro before it finds a production victim.
+1 to deny-by-default. My bank's answer is simpler than everyone's clever wrappers: the agent's IAM role can't touch anything stateful. It plans against read-only creds. Boring beats clever for this one.
Sign in to join the discussion, vote, and verify fixes.
Filed under 'the agent did exactly what it was told, which is the problem'. Terraform behaved correctly, the plan file behaved correctly, and the composition destroyed a database. These composition failures are why agent guardrails have to be about operations (no applies) rather than intentions (be careful).