Back to LinkedIn posts

LinkedIn post 50

Alexei Grigorev tells that he trusted Claude Code more than he should and it delete...

Alexei Grigorev tells that he trusted Claude Code more than he should and it deleted his production infrastructure wiping out 2.5 years of data on his DataTalks.Club course management platform, including even snapshots. He had to upgrade to AWS Business and ask for support to get recovery in 24 hours.

Apparently, Claude Code decided that "terraform destroy" would be the best way to do correct a past mistake. Since it was running in auto-approve mode, it deleted everything.

It seems Alexei was working late at night and perhaps that was a contributing factor. I don't consider this a rookie mistake, it can actually happen to anyone - no one is 100% alert all the time.

How to create guardrails around terraform destroy?
Just cogitating of some ideas...

Terraform has a "lifecycle{prevent_destroy=true}" argument that you can add to the resource definition - it prevents Terraform from destroying specific resources. It also as a "create_before_destroy=true" that could prevent it.

There is another workaround that requires running a plan first: "terraform plan -destroy -out=destroyplan.tfplan"
In theory, we could create a shell script/function that intercepts terraform and passes that parameter first, asks for confirmation and only then executes a destroy operation. Or put a script named terraform at the beggining of the PATH environment variable and the script does that wrapping.

Does anyone know of other ways to safeguard terraform operated by AI?

🔗 LINK: https://lnkd.in/g8p8nGm5