Skip to content
Latchkey

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 UTC

Common 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

  1. Confirm no run actually holds the lock (check CI and the lock metadata timestamp).
  2. Run terraform force-unlock <ID> with the ID from the error.
  3. 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-timeout to ride out brief contention.
  • Alert on locks held longer than a run should take.

Related guides

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