You inherited a stack whose state lives in a committed `terraform.tfstate` in Git. Three engineers have different versions locally.
AdvancedTroubleshootingLost, Corrupted and Drifted State
Answer
Likely causes → No remote backend; each engineer applied from their own copy, so the copies forked.
Diagnose →
git log --oneline -- terraform.tfstate
for f in a.tfstate b.tfstate c.tfstate; do jq -r '"\(.serial) \(.lineage) \(.resources|length)"' $f; done
Also scan the state for secrets: it's in Git history.
Fix → Pick the most complete copy (highest serial, same lineage), import anything others created, migrate to S3 with terraform init -migrate-state, delete the file from the repo and add *.tfstate* to .gitignore. Rotate any secrets found in history.
Prevent → Remote backend with locking from day one; pre-commit hook blocking *.tfstate.
More on Lost, Corrupted and Drifted State
Someone deleted the state object from the S3 bucket. `terraform plan` now wants to create 140 resources that already exist.IntermediateState is gone and the bucket had no versioning. How do you recover a production stack?Advanced`Error: Failed to load state` followed by a JSON error like `invalid character '}' looking for beginning of object key string`.IntermediateThe plan prints `Note: Objects have changed outside of Terraform` and lists a security group with an extra ingress rule.BeginnerEvery plan wants to change `desired_capacity` on an Auto Scaling group back to 2, though autoscaling has raised it to 6.BeginnerA resource was deleted manually in the console. The plan wants to create it, and an apply fails because a dependent resource still references the old ID.Intermediate