Interview Prep/Terraform/State Locking and Backend Errors

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

All Terraform questions Roadmap: Terraform in production

More on State Locking and Backend Errors