`terraform plan` fails with `Error acquiring the state lock` and `ConditionalCheckFailedException: The conditional request failed`.
BeginnerTroubleshootingState Locking and Backend Errors
Answer
Likely causes → Another plan/apply holds the lock right now; a previous run crashed (CI runner killed, laptop closed, Ctrl-C twice) and left the lock item in DynamoDB.
Diagnose → The error prints Lock Info with ID, Who, Operation and Created. Check whether that person or pipeline is still running.
aws dynamodb scan --table-name terraform-locks \
--query 'Items[].{id:LockID.S,info:Info.S}'
Fix → If a run is active, wait. If the holder is confirmed dead, release it with the lock ID from the message:
terraform force-unlock 6f1c2a9e-3b1d-4c7a-9a0e-2d5f8f1b7c11
Prevent → Serialize pipelines per stack (CI concurrency groups), give CI jobs a graceful timeout so Terraform can release the lock, and never use -lock=false on shared state.
More on State Locking and Backend Errors
With 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`Error: Backend initialization required, please run "terraform init"` with `Reason: Initial configuration of the requested backend "s3"`.Beginner