Terraform "Error acquiring the state lock" - lock already held in CI
Terraform takes an exclusive lock on state before any write. When another run holds it - concurrent pipeline or a crashed run that never released it - the new run cannot acquire the lock.
What this error means
terraform plan/apply fails acquiring the state lock and prints the existing lock's ID, who/what holds it, and when it was created.
terraform
Error: Error acquiring the state lock
Lock Info:
ID: 9db590f1-3e2a-...
Path: tf-state-prod/prod/terraform.tfstate
Operation: OperationTypeApply
Who: runner@ci
Created: 2026-06-26 09:41:12.0 +0000 UTCCommon causes
Concurrent runs on the same state
Two pipeline jobs (or a manual run plus CI) target the same workspace at once.
Crashed run left a stale lock
A previous run was killed before releasing the lock, so it persists.
How to fix it
Wait for or serialize the concurrent run
If another run is genuinely active, let it finish or enforce single-flight per workspace.
Force-unlock a confirmed stale lock
- Confirm no run actually holds the lock (check CI and the lock metadata timestamp).
- Run
terraform force-unlock <ID>with the ID from the error. - Re-run plan/apply.
Terminal
terraform force-unlock 9db590f1-3e2a-...How to prevent it
- Use concurrency groups so only one Terraform job per workspace runs at a time.
- Set a sensible
-lock-timeoutto ride out brief contention. - Alert on locks held longer than a run should take.
Related guides
Terraform "Error acquiring the state lock" - DynamoDB at init in CIFix Terraform "Error acquiring the state lock" against a DynamoDB lock table in CI - a missing table, missing…
Terraform "force-unlock failed" / Lock ID does not match in CIFix Terraform force-unlock failures in CI - the lock ID does not match, the backend denies the delete, or the…
Terraform "Failed to load state: AccessDenied" in CIFix Terraform "Failed to load state: AccessDenied" in CI - the runner cannot read the remote state object (mi…