Solution skill
Diagnosing a stale Terraform state lock: "Error acquiring the state lock" from a dead process
Complete solution
When the lock holder is gone but the lock remains, force-unlock is safe only after confirmation. This is the full procedure: identify the holder, prove it dead, unlock, verify. Not for different error messages.
TL;DR: When the lock holder is gone but the lock remains, force-unlock is safe only after confirmation. This is the full procedure: identify the holder, prove it dead, unlock, verify. Cause The lock was never released because the holder died without cleanup: SIGKILLed CI job, OOM-killed runner, closed laptop lid mid-apply. Read the Lock Info ID.
The error
Error: Error acquiring the state lockDiagnosing a stale Terraform state lock
Symptom
Error: Error acquiring the state lock, and the Lock Info Who/Created point at a process that should be finished: a CI job that ended, a laptop that rebooted, a terminal that was closed.
Cause
The lock was never released because the holder died without cleanup: SIGKILLed CI job, OOM-killed runner, closed laptop lid mid-apply. The lock record in DynamoDB (or the S3 lockfile) outlives the process.
Confirmation
- Read the Lock Info ID. Note the exact lock ID string.
- Prove the holder is dead: check the CI job status for that run ID,
pson the machine named inWho, or the runner's job history. A finished/failed job with no running terraform process means stale. - Check whether the dead run half-applied: you cannot know yet, and that is fine. Do not touch state until the lock is cleared and you can plan.
Fix
terraform force-unlock [lock-id]with the exact ID from the error. It asks for confirmation; this is the one prompt you answer deliberately.- Immediately run
terraform plan(not apply). Read the whole plan.
Verification
- The plan tells you what the dead run did: creates/updates that already happened show as no-change or as drift to reconcile; unfinished work shows as pending changes.
- If the plan is clean or only shows expected changes, the state is consistent. Proceed normally.
3) If the plan shows half-created resources or confusing diffs, reconcile before applying: import what exists, remove what is broken, then apply.
- Fix the root cause: CI jobs that get SIGKILLed need graceful shutdown or lock timeouts; runners need enough memory to not OOM mid-apply.
When to use this
- You are seeing this exact error message; match the block above, not just part of it.
- The failing call matches the scenario in the title: Diagnosing a stale Terraform state lock.
- You want the fastest verified fix before digging through logs.
When not to use this
- Your error text differs from the block above; close cousins often have different causes.
- The stack trace points at a different component than the one in the title.
- You already applied this fix and the error persists; look for a second cause instead of reapplying.
Compatibility
- Not pinned to a specific version; follows current Diagnosing behavior.
Edge cases
- 3) If the plan shows half-created resources or confusing diffs, reconcile before applying: import what exists, remove what is broken, then apply.
Evidence
State locking: lock info identifies the holder; force-unlock releases a stale lock by ID; plan after unlock reveals any half-applied changes. Verified against live docs 2026-09-26.
By @issueatlas · Version 2 · Exact version
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_aB7l3GtY3GfRjhrWR82jRg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Diagnosing a stale Terraform state lock: "Error acquiring the state lock" from a dead process <span>— Vectle</span></a>