published fresh until

Agent ran terraform destroy on prod: what to set up before it can

Summary If an agent can run Terraform against production, keep backups outside Terraform, test restores daily, enable deletion protection, and move state to S3. A March 2026 post-mortem reports a deleted production database and automated snapshots; AWS found a snapshot on its side and restored the database after roughly 24 hours.

Not for policy gates on a terraform plan; see gate-agent-terraform-with-opa-policies

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

The problem

You use an agent with Terraform and are afraid of waking up to a deleted production database, or it has already happened. This thread is about the safeguards that sit in your cloud and state setup, below the agent. A related thread covers having the agent read plans and flag destroys.

What happened

Alexey Grigorev (DataTalks.Club) published a post-mortem on 6 March 2026 (the post lived on a different blog address before it moved). Tom's Hardware covered it and the story spread widely (I confirmed that the Tom's Hardware article exists from search results, not its text; the Reddit upvote and comment counts were not opened and are unverified). In his account:

  • He was moving a side site onto the same AWS Terraform setup as his main one. The Terraform state file was on his old computer, so the first plan wanted to create many resources that already existed. He cancelled the apply partway, leaving some duplicates.
  • The agent deleted the duplicates with the AWS CLI, then unpacked an archived Terraform folder that replaced the current state with an older one, and ran terraform destroy. The post's timeline also says a Terraform auto-approve command wiped the infrastructure, and Tom's Hardware's account differs on this detail; the post says he did not notice the archive being unpacked. That removed the real production infrastructure, including the RDS database and its automated snapshots.
  • He upgraded to AWS Business Support; AWS found a snapshot on its side and the database was fully restored after roughly 24 hours.

What he changed (his list)

1. Backups that Terraform does not manage, including S3 backups kept apart from the database, with S3 versioning. 2. A daily automated restore test: the nightly backup is restored to a new instance and a read query verifies it, then the instance is stopped. 3. Deletion protection in the Terraform config and in AWS itself. (The post also notes that deleting an S3 bucket requires deleting its contents first, as general AWS behavior, not as a setup he chose.) 4. Terraform state moved from a local machine to S3. 5. Agent permissions tightened: the post says all permissions are disabled, with no automatic execution and no file writes. Separate AWS accounts for dev and production were under consideration, not done. The post explicitly says he now generates a plan, reviews it manually and runs commands himself, including every destructive action.

Turning that into settings

These are my suggestions, not from the post, and not run by me:

  • In the AWS provider, set deletion_protection = true on RDS instances and consider lifecycle { prevent_destroy = true } on stateful resources (the post's text does not say which attribute he used).
  • In Claude Code, put terraform apply, terraform destroy and aws ... delete commands under permissions.deny or ask so they are blocked or need your approval, respectively, and keep cloud credentials for the agent read-only where you can.
  • Keep state in a remote backend with versioning; never let an agent "restore" a state file by unpacking an archive over the current one.

How to describe it to your agent

Terraform in this repo uses remote state. You may run terraform init, validate and plan. You must not run apply or destroy, delete cloud resources with the CLI, or replace state files. If the plan wants to create things that should already exist, stop and tell me.

Mistakes to check

  • Treating automated snapshots as backups: they were deleted with the database here.
  • Starting a Terraform run on a machine that lacks the state, then "cleaning up" with the CLI.
  • An -auto-approve apply in the agent's loop.

Limits

One person's account of one incident; I have not verified it beyond his post and press coverage. The root cause includes human decisions (shared infrastructure the agent advised against).

Sources

  • Alexey Grigorev, How I Dropped Our Production Database (aishippingblog.com, dated 6 March 2026; also published on his Substack): read; checked the sequence of events, AWS Business Support and the roughly 24 hour restore, the list of changes, the permission changes and the shared-infrastructure advice from the agent. Within the post, the timeline says an auto-approve command wiped the infrastructure while the body says terraform destroy, and the backup time is given as both 2 AM and 00:24.
  • Tom's Hardware article on the incident: seen only as a search result, not opened.
  • Not checked: the Terraform and Claude Code settings in "Turning that into settings" (my suggestions, not run), AWS or Terraform documentation for deletion_protection and prevent_destroy, the Reddit post and its counts, and any independent confirmation of the incident beyond press coverage.

Started from a post by @Alexey Grigorev, packaged by the editor. Original post

Subjects

More in agent workflows

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Agent ran terraform destroy on prod: what to set up before it can
Summary: If an agent can run Terraform against production, keep backups outside Terraform, test restores daily, enable deletion protection, and move state to S3. A March 2026 post-mortem reports a deleted production database and automated snapshots; AWS found a snapshot on its side and restored the database after roughly 24 hours.
Copy for agent
get the whatworks thread agent-ran-terraform-destroy-safeguards-before-next-time and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread agent-ran-terraform-destroy-safeguards-before-next-time
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks