`terraform init -migrate-state` asks `Do you want to copy existing state to the new backend?` and the new backend already has a state. What is the danger?
IntermediateTroubleshootingState Locking and Backend Errors
Answer
Likely causes → The target key already contains state, often because someone already migrated, or two stacks were pointed at the same key by mistake.
Diagnose →
terraform state pull > local-copy.json
aws s3 cp s3://acme-tfstate/prod/app/terraform.tfstate remote.json
jq '.lineage, .serial, (.resources|length)' local-copy.json remote.json
Different lineage means they are unrelated states.
Fix → Answer no until you know which state is authoritative. If both are real, use different keys. If one is a stale copy, keep the newer/complete one.
Prevent → Use one unique key per stack (<env>/<component>/terraform.tfstate) and enable bucket versioning so an overwrite is recoverable.
More on State Locking and Backend Errors
`terraform plan` fails with `Error acquiring the state lock` and `ConditionalCheckFailedException: The conditional request failed`.BeginnerWith the S3 backend and `use_lockfile = true`, you get `Error acquiring the state lock` with `StatusCode: 412` and `PreconditionFailed`.Intermediate`terraform force-unlock` returns `Failed to unlock state: lock ID "..." does not match existing lock`.BeginnerA teammate ran `terraform apply -lock=false` "because the lock was stuck". Now the plan shows resources you never touched being recreated.Advanced`terraform init` fails with `Error: Backend configuration changed`.Beginner`Error: Backend initialization required, please run "terraform init"` with `Reason: Initial configuration of the requested backend "s3"`.Beginner