Menu

Terraform state gotchas I wish someone had told me on day one
📰

Terraform state gotchas I wish someone had told me on day one

DEV Community: terraform·Ayodele·10 days ago
#2OQPTXa0
#devtoterraform#devto#dev#terraform#state
Reading 0:00
15s threshold

AI-assisted: I wrote the outline and the examples, and used an AI tool to tighten the wording. I checked the behaviour below against HashiCorp's documentation. I run LearnSome.tech, where we teach Terraform; this post doesn't need anything from it.

Terraform's state file is easy to ignore until it bites. It's the record that says "this address in my code owns that real thing in the cloud". Lose it or share it carelessly and Terraform's view of the world stops matching reality. These are the gotchas I see most often.

1. Deleting state doesn't delete anything, and that's the problem

Delete terraform.tfstate and your cloud resources are untouched. But Terraform has forgotten they're yours. The next apply plans to create everything again, and you either get duplicates or name clashes.

If you've lost state but the resources exist, don't recreate them. Bring them back under management with terraform import or an import block, then check terraform plan shows no changes.

2.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.