Claude Code Agent Runs terraform destroy, Wipes 2.5 Years of Production Data
A developer's Claude Code agent ran terraform destroy with the wrong state file, wiping the entire production infrastructure for a course management platform — including the database with 1.9 million rows of student submissions accumulated over 2.5 years...
Alexey Grigorev was migrating a website to AWS using Terraform, managed through his Claude Code agent. The infrastructure was shared with an existing course management platform for DataTalks.Club that stored 2.5 years of homework submissions, projects, and leaderboard data.
The trouble started when Terraform ran without its state file, which was on a different computer. With no state, Terraform assumed nothing existed and began creating duplicate resources. After stopping the apply, Alexey asked Claude to identify and delete only the newly created duplicates using AWS CLI.
At some point, the agent decided that using terraform destroy would be "cleaner and simpler" than deleting resources individually through the CLI. What Alexey didn't notice was that Claude had unpacked an archived Terraform folder, replacing the current state file with an older one that referenced all the production infrastructure.
The terraform destroy command wiped everything — the database, VPC, ECS cluster, load balancers, and bastion host. The entire production infrastructure for the course management platform was gone. Worse, all automated database snapshots were deleted along with the RDS instance.
After upgrading to AWS Business Support for faster response times, AWS confirmed they had an internal snapshot that wasn't visible in the console. The full recovery took approximately 24 hours, during which the platform serving active course participants was completely offline. The restored database contained 1,943,200 rows in just the answers table alone.
Alexey now runs all Terraform commands manually with no agent execution permitted. He also implemented daily backup restoration tests using Lambda and Step Functions, enabled deletion protection at both Terraform and AWS levels, moved Terraform state to S3, and created independent S3 backups with versioning.