Skip to content

Gotcha: Terraform state lock not released

A cancelled CI job leaves the S3/DynamoDB state lock behind and every later plan fails.

Gotcha
  • #terraform
  • #debug
  • #github-actions
Created Updated

Also:Error acquiring the state lock · ConditionalCheckFailedException · state lock · tf lock · tf · force-unlock

The surprise: after cancelling a GitHub Actions run mid-apply, every following terraform plan failed with:

Error: Error acquiring the state lock
Error message: ConditionalCheckFailedException: The conditional request failed
Lock Info:
ID: 4b7f0c3e-91d2-6a55-0f1e-2c9a8d7e5b10
Operation: OperationTypeApply
Who: runner@fv-az123-456

Why: cancelling a job sends SIGKILL to the runner shortly after SIGTERM, so Terraform doesn’t get to delete its lock item in DynamoDB.

Fix / do this instead:

  1. Make sure nothing is still running against that state (check other CI runs, colleagues).
  2. Release it with the ID from the error: Terraform: Release a stuck state lock
Terminal window
terraform force-unlock 4b7f0c3e-91d2-6a55-0f1e-2c9a8d7e5b10
  1. Prevent it: add a concurrency: group per workspace in the workflow and avoid cancelling apply jobs. Cancel plan jobs only.
concurrency:
group: terraform-${{ github.ref }}-prod
cancel-in-progress: false

Seen in: prod networking stack, 2026-11-12.

My DevOps Playbook by Angelo John Calleja

New runbook

GitHub not connected

Saving is handled by the site: the GitHub token is stored in Cloudflare, not in your browser. Enter the editor password (the EDITOR_PASSWORD secret) to unlock saving in this browser.

Saving commits to gelogrammer/My_DevOps_Playbook. Create a fine-grained token with access to only this repo andContents: Read and write, then paste it here. It is stored only in this browser.

src/content/docs/…