Apply was cancelled in GitHub Actions. The next run fails with the state lock held by `Who: runner@fv-az123` and the plan shows half the resources changed.
AdvancedTroubleshootingState Locking and Backend Errors
Answer
Likely causes → Cancelling a job sends SIGINT then kills the process after a short grace period. Terraform could not finish writing state or releasing the lock.
Diagnose → Check the cancelled run's log for the last Creation complete / Modifications complete lines and whether errored.tfstate was uploaded. Confirm no other runner is active.
Fix → terraform force-unlock <ID>, then terraform plan. Resources finished before the kill are usually in state (Terraform persists state periodically during apply). Import anything the log shows as created but the plan wants to create again.
Prevent → Don't cancel applies; use concurrency: { group: tf-prod, cancel-in-progress: false }. Set timeout-minutes generously and upload errored.tfstate on failure.
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