Gotcha: Terraform state lock not released
A cancelled CI job leaves the S3/DynamoDB state lock behind and every later plan fails.
Gotcha: Terraform state lock not released · #terraform #debug #github-actionsGotcha
The surprise: after cancelling a GitHub Actions run mid-apply, every following terraform plan failed with:
Error: Error acquiring the state lockError message: ConditionalCheckFailedException: The conditional request failedLock Info: ID: 4b7f0c3e-91d2-6a55-0f1e-2c9a8d7e5b10 Operation: OperationTypeApply Who: runner@fv-az123-456Why: 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:
- Make sure nothing is still running against that state (check other CI runs, colleagues).
- Release it with the ID from the error: Terraform: Release a stuck state lock
terraform force-unlock 4b7f0c3e-91d2-6a55-0f1e-2c9a8d7e5b10- Prevent it: add a
concurrency:group per workspace in the workflow and avoid cancellingapplyjobs. Cancelplanjobs only.
concurrency: group: terraform-${{ github.ref }}-prod cancel-in-progress: falseSeen in: prod networking stack, 2026-11-12.
My DevOps Playbook by Angelo John Calleja