MistakeClaude Code with Terraform

Claude Code ran terraform destroy and took down a production platform

Helping move a new site into existing AWS infrastructure, Claude Code swapped in an old Terraform state file and ran terraform destroy, deleting the DataTalks.Club course platform’s database and its snapshots.

By the NoFly team

What NoFly would decideIllustrative
Waiting for a personClaude Code hook
terraform destroy -auto-approve
Agent
Claude Code
Came from
The agent’s own clean-up plan
Rule
Destroying production infrastructure needs a person
Why
terraform destroy with auto-approve, against the workspace that runs production.
Approve onceDenyAn unanswered hold expires as a no

What happened

Alexey Grigorev wanted to add his AI Shipping Labs site to the Terraform setup that ran DataTalks.Club’s production infrastructure, although Claude had suggested keeping them separate. On a new computer without the Terraform state file, the agent began creating duplicate resources, and he asked it to clean them up.

The agent unpacked an older Terraform archive, which put back a state file describing the real production setup, said a terraform destroy would be cleaner, and ran it. The VPC, ECS cluster, load balancers, bastion host and database were deleted, and the automated snapshots with them, including two and a half years of course submissions.

After he upgraded to AWS Business Support, AWS found a snapshot that was not visible in his console and restored the database about a day later. He published the post-mortem on 6 March 2026.

  1. 01

    A new site is added to the Terraform setup that already runs production.

  2. 02

    Without the state file, the agent starts creating duplicates.

  3. 03

    Cleaning up, it restores an old state file that describes production.

  4. 04

    It runs terraform destroy, and production and its snapshots are deleted.

  5. 05

    AWS support restores a snapshot about a day later.

Why it worked

Probable cause

An agent could run Terraform with auto-approve against production, using a state file it had swapped in, with no deletion protection and with backups tied to the resources being destroyed.

How NoFly stops it

  • Protect

    The gate inside Claude Code sees terraform destroy before it runs. With your policy connected, a destroy or an auto-approved apply against production is held for a person.

  • Govern

    Rules can be stricter in production than anywhere else, so work on a new site cannot reach the environment that already runs the business.

What to do this week

This week4 actions
  1. Keep Terraform state in a shared backend, never only on one laptop.
  2. Turn on deletion protection for databases, and keep snapshots outside what an agent can destroy.
  3. Never let an agent run apply or destroy with auto-approve against production.
  4. Test restoring from backup on a schedule.
Keep reading

More from the blog.

Find out what your AI is allowed to do today.

Book a call and we will map your agents, MCP servers and keys with you, or start on one laptop with the free scan.

Book a demo
npm i -g @nofly/agent