Terraform State
The one file whose loss will cost you your weekend.
State: The Central and Most Fragile Piece
Two people are working on the same infrastructure. The first adds a message queue, applies, and goes to lunch. The second pulled the repository an hour earlier, with their own local terraform.tfstate that knows nothing about the queue. They add a database and apply. Their state doesn't contain the queue, so Terraform concludes the queue doesn't exist and that it has nothing to do with it. That holds until the day someone runs terraform destroy against one of the two states and destroys half the infrastructure, leaving the other half orphaned, unmanageable, and still billed.
This scenario doesn't happen because people are careless. It happens because the default state is a local file, and a local file is invisible to everyone else. State is neither a cache nor a log: it is the only thing that links a line of your code to a real object at the provider. Without it, Terraform doesn't know that aws_s3_bucket.artefacts corresponds to the bucket skillverse-artefacts-demo-4821. It concludes that it needs to create it, and it tries.
Comments
Comments are powered by GitHub Discussions
Sign in with GitHub to join the discussion