Terraform State Locking: Why You Need It and How It Goes Wrong

Terraform state without locking is a bug waiting to happen. Two engineers running apply simultaneously can corrupt state in ways that take hours to untangle. Here’s what I learned after one such incident. Why state locking matters Terraform reads state, computes a plan, and writes new state. Without locking, two concurrent runs can: Both read the same initial state Both compute their plans based on it Both write conflicting state — last one wins Now state doesn’t match real infrastructure The symptoms are weird: resources exist but Terraform wants to create them again. Or state references resources that were already destroyed. ...

September 18, 2024 · 2 min · Besterry