Skip to content
Latchkey

Terraform "Error acquiring the state lock" in CI

Terraform could not take the state lock before the operation. Another concurrent run holds it, or a previous job crashed without releasing it and left a stale lock. The message prints the Lock ID needed for a manual unlock.

What this error means

plan or apply stops with "Error: Error acquiring the state lock" and a "Lock Info" block showing ID, Who, Created, and often a lock backend such as DynamoDB.

Terraform
Error: Error acquiring the state lock

Error message: operation error DynamoDB: PutItem, ConditionalCheckFailedException
Lock Info:
  ID:        3f2b1a9c-2b7e-4c1d-9f2a-...
  Operation: OperationTypeApply
  Who:       runner@ci
  Created:   2026-06-30 12:00:00 UTC

Common causes

A concurrent run holds the lock

Two pipelines target the same state at once; the second cannot acquire the lock until the first finishes.

A crashed job left a stale lock

A cancelled or killed run never released the lock, so the row/object persists and blocks new runs.

How to fix it

Force-unlock a confirmed stale lock

  1. Confirm no job is actually running against that state.
  2. Copy the Lock ID from the error output.
  3. Run terraform force-unlock <ID> to release it, then re-run.
Terminal
terraform force-unlock 3f2b1a9c-2b7e-4c1d-9f2a-...

Serialize runs against the same state

Use a concurrency group so only one pipeline touches a given state at a time, avoiding contention.

.github/workflows/ci.yml
concurrency:
  group: tf-${{ github.ref }}
  cancel-in-progress: false

How to prevent it

  • Serialize Terraform jobs per state with a concurrency group.
  • Only force-unlock after confirming no run is active.
  • Let jobs finish cleanly so locks release themselves.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →