Interview Prep/Terraform/State Locking and Backend Errors

`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.

All Terraform questions Roadmap: Terraform in production

More on State Locking and Backend Errors