Terraform fails with "Error acquiring the state lock". What happened and how do you resolve it?
Quick Answer
Another operation holds the state lock (a running apply, or a crashed run that left a stale lock). Wait for the other run, or if it is genuinely stale, release it with terraform force-unlock <lock-id> after confirming no apply is in progress.
Detailed Answer
Remote backends (S3+DynamoDB, Terraform Cloud, GCS) lock state to prevent concurrent applies corrupting it. The error prints the lock ID, who holds it, and when. First confirm no real apply is running (CI job, teammate). Only then terraform force-unlock <lock-id>. Prevent it by serializing applies in CI and never Ctrl-C-ing an apply mid-run.
Code Example
terraform force-unlock <lock-id> # only after confirming no apply is running
Interview Tip
Stress confirming no apply is actually running before force-unlock — forcing during a live apply corrupts state.