🔒

Terraform state lock stuck

plan/apply blocked by DynamoDB or remote backend lock — release safely.

Reviewed: ·Tested on: Kubernetes 1.29, Terraform 1.8, Ubuntu 22.04

Symptoms

  • Error: Error acquiring the state lock
  • Another process is holding a lock on the state
  • CI job was cancelled mid-apply

1Confirm no real apply is running

Check CI/CD and teammates before force-unlocking. A running apply must finish first.

2Inspect lock metadata

The error message includes Lock ID and who holds the lock. Note the ID for unlock.

terraform plan   # re-read lock info in error output

3Force unlock (after confirming safe)

terraform force-unlock <LOCK_ID>

4Prevent recurrence

Use plan-only in PRs, serialize applies on main, and set CI timeout cleanup. Consider state locking with S3 + DynamoDB best practices.

terraform init -reconfigure
terraform workspace list

Related