A plan wants to destroy and recreate a whole module after a teammate restored state from a backup taken before a big refactor.
AdvancedTroubleshootingLost, Corrupted and Drifted State
Answer
Likely causes → The backup predates moved/state mv operations, so the restored state uses the old addresses while code uses new ones. If the moved blocks were deleted already, Terraform can't map them.
Diagnose → terraform state list | head and compare to code addresses (module.network.aws_vpc.this vs aws_vpc.main).
Fix → Re-add the moved blocks (or run the same terraform state mv commands) and re-plan until the destroys disappear. Then import anything created after the backup.
Prevent → Keep moved blocks in code for a long time (several releases), and take a state pull backup right before every refactor, not days earlier.
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