Back to troubleshooting
troubleshooting#terraform#state#debugging

Terraform: state lock error (already locked by another process)

Fix the classic 'Error acquiring the state lock' without corrupting your state file.

Jane Contributor August 2, 2026 1 views

Problem

Running `terraform apply` fails with `Error acquiring the state lock`. It says the lock is held by another operation, but nobody is running Terraform.

Step-by-step Solution

  1. 1Read the error message carefully — it shows the lock ID, who acquired it, and how long ago. If the lock was acquired more than a few minutes ago and no one is actively running Terraform, it's stale (a crashed run left it behind).
  2. 2Ask on the team channel: 'Is anyone running Terraform on <workspace>?' Wait 60 seconds before touching anything.
  3. 3If confirmed stale, force-unlock: `terraform force-unlock <LOCK_ID>`. Terraform will confirm before removing.
  4. 4Common causes: a previous run was killed with Ctrl-C too aggressively, a CI job timed out mid-apply, a laptop lost network mid-apply, or DynamoDB (the lock table for the S3 backend) had a hiccup.
  5. 5Prevent recurrence: enable CI job timeouts *shorter* than the lock timeout; ensure only one CI pipeline touches a given workspace; use `terraform apply -lock-timeout=5m` so runs wait a bit instead of failing instantly.
  6. 6Never edit the DynamoDB lock table by hand unless you *really* know what you're doing — you can corrupt state by unlocking mid-apply.

See problem and step-by-step solution above.

Keep reading

You may also like

Discussion (0)

No comments yet. Be the first to weigh in.

Leave a comment

Comments are reviewed before appearing.