recover-from-a-stale-state-lock
Use when terraform refuses to run because the state lock is held by a crashed or killed run. Verifies the holder is dead before force-unlocking, never disabling locking.
- License 许可
- MIT
- 最近更新
- 2026-11-14
- Stars
- ★ 81
- Forks
- 17
01 前言 Front Matter
- name
- recover-from-a-stale-state-lock
- description
- Use when terraform refuses to run because the state lock is held by a crashed or killed run. Verifies the holder is dead before force-unlocking, never disabling locking.
02 资源文件 3
- 许可证LICENSE1.0 KB
- 参考文档SOURCE.md357 B
- 参考文档TRUST.auto.yaml2.2 KB
03 SKILL.md 正文
Recover from a stale state lock
A crash or killed CI job leaves a lock with no process behind it. Force-unlocking a lock that is still held corrupts state; confirm the holder is gone first.
Procedure
- Read who holds the lock; the error names the ID, path, and operation: Error: Error acquiring the state lock ID: 8f3c... Operation: OperationTypeApply Who: ci-runner@...
- For S3+DynamoDB, inspect the lock row:
aws dynamodb get-item --table-name tf-locks
--key '{"LockID":{"S":"acme-tfstate/prod/terraform.tfstate"}}' - Confirm no live process holds it: the CI job that owns the ID is finished or failed, and no
terraform applyruns on that runner. ps aux | grep '[t]erraform apply' - Only then force-unlock with the exact ID from the error: terraform force-unlock 8f3c-...
- If a run genuinely is in progress, wait for it;
-lock-timeout=5mmakes waiting automatic. - After force-unlock, immediately
terraform planto confirm state is intact and consistent. - Do not delete the DynamoDB row by hand instead of force-unlock; the CLI also notifies the backend and keeps lock metadata consistent.
- Fix the root cause: set
-lock-timeout, add CI concurrency limits, and ensure killed jobs do not orphan locks.
Pitfalls
- Force-unlocking a lock held by a live apply, so two writers interleave and corrupt state.
- Deleting the lock table row manually, leaving the backend's lock metadata inconsistent.
-lock=falseas a "fix", removing locking for every future run.- Force-unlocking with a guessed ID; the CLI requires the real one, and people work around it by deleting the row.
- Not running a plan after unlock, so pre-existing corruption surfaces at the next apply.
Verification
aws dynamodb get-item --table-name tf-locks \
--key '{"LockID":{"S":"acme-tfstate/prod/terraform.tfstate"}}' # Item: null after unlock
terraform plan # acquires lock, no errors
Report: the stale lock ID, the evidence the holder was dead, the force-unlock result, and the clean plan afterward.
04 同仓库更多 Skills
recipe-performance
Diagnose a specific MetaMask user flow's real-app performance and Sentry critical-user-flow telemetry with deterministic mm-harness recipes. Use for CUF boundaries, cold/warm/background-resume behavior, latency regressions, lifecycle tags, duplicate or blocking network requests, long tasks, layout/paint cost, screen redraws, React rerenders, or browser trace analysis where tests alone cannot prove the real app.
mexc-spot-websocket
MEXC Spot WebSocket workflows for public streams, protobuf handling, depth maintenance, listen keys, and private streams without exposing API keys.
mexc-spot-rest
MEXC Spot REST workflows for public data, signed account requests, orders, wallet/admin actions, and secure signing without exposing API keys.
mexc-futures-websocket
MEXC Futures WebSocket workflows for public streams, private account/order/position streams, ping/pong, subscriptions, and depth maintenance.
0xklen-version-and-refresh-sanctions-lists
暂无简介
verify-tests-cover-changed-lines
Use when a PR adds code that the existing suite may not exercise. Measures patch coverage — the share of newly changed lines hit by tests — before approving.