`terraform state push` fails with `cannot import state with lineage "a1..." over unrelated state with lineage "b2..."`.
IntermediateTroubleshootingState Locking and Backend Errors
Answer
Likely causes → The file you push came from a different stack or a re-created state (new lineage). Terraform protects you from overwriting an unrelated state.
Diagnose →
terraform state pull | jq '.lineage, .serial'
jq '.lineage, .serial' errored.tfstate
Fix → Make sure you are in the right directory/workspace/backend key. Only if you are certain the file is the correct one, use terraform state push -force file.tfstate, after taking a state pull backup.
Prevent → Never copy state files between stacks. Use terraform state mv -state-out or removed + import for moving resources.
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`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?Intermediate