So, I have a funny story. I was testing a new app in Terraform, and thought it would be a good idea to define my Terraform State bucket and lock table in the Terraform code. Everything went well, all my infrastructure was defined as code, and for a while everything was perfect…
Then I decided to move my app from us-east-2
to us-east-1
, so I ran terraform destroy
and go walk my dog.
Lo and behold - that was a Noob move. Terraform deleted my state bucket and table too early, and the operation failed.
There is probably a way to make Terraform delete those resources last, but I think its safest to simply create them outside of your IaC. Here is a quick CLI script to make it simple.
Create Terraform State Resources Commands
1 | aws s3api create-bucket --bucket my-tf-state |