Skip to content
Latchkey

Terragrunt "Error acquiring the state lock" during run-all in CI

A run-all executes many units concurrently. If two units share a state, or a previous killed job left a DynamoDB lock behind, Terraform cannot acquire the state lock and the run fails. Terragrunt runs distinct units in parallel, so contention is a run-all-specific pitfall.

What this error means

A run-all apply fails with "Error acquiring the state lock" and a Lock Info block showing an existing lock ID, often from a job that was cancelled mid-run.

terragrunt
Error: Error acquiring the state lock

Error message: operation error DynamoDB: PutItem, ConditionalCheckFailedException:
the conditional request failed
Lock Info:
  ID:        7f3c9a12-...
  Operation: OperationTypeApply
  Created:   2026-06-30 10:12:03 UTC

Common causes

A stale lock from a cancelled job

A prior run was cancelled or the runner was killed before releasing the lock, so the DynamoDB lock row persists and blocks the next run.

Two units contend for the same state

A misconfigured backend key gives two run-all units the same state path, so their parallel apply fights over one lock.

How to fix it

Release a confirmed-stale lock

  1. Confirm no other job is actually running against that state.
  2. Release the lock with force-unlock using the reported lock ID.
  3. Re-run the pipeline.
Terminal
terragrunt force-unlock 7f3c9a12-... --terragrunt-working-dir live/prod/vpc

Give each unit a unique state key

Derive the backend key from the module path so no two units share state.

terragrunt.hcl
key = "${path_relative_to_include()}/terraform.tfstate"

How to prevent it

  • Use path_relative_to_include() so every unit has a distinct state.
  • Avoid cancelling jobs mid-apply; let them release the lock.
  • Lower --terragrunt-parallelism if lock contention is frequent.

Related guides

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