Terraform
Sep 30, 2025 4 min read

Fix Terraform "Error acquiring the state lock"

What to do when Terraform refuses to plan because the state is locked — and how to avoid it.

Problem

bash
Error: Error acquiring the state lock
Lock Info:
  ID:        2c3a...
  Operation: OperationTypePlan
  Who:       ci@runner-9
  Created:   2026-05-15 09:12:33

Root cause

Another `terraform` invocation holds the lock — usually a CI job that crashed before releasing it. The lock entry sits in DynamoDB (S3 backend) or the equivalent for your backend.

Solution

Confirm no real job is still running

Check CI logs and any teammate's terminal. Force-unlocking a live job will corrupt your state.

Force unlock

bash
terraform force-unlock 2c3a...

Prevent it next time

  • Wrap CI runs with a trap that releases the lock on failure.
  • Set a sane `-lock-timeout=120s`.
  • Don't share one state across many concurrent CI jobs — split workspaces.

Frequently asked questions

Related fixes

Weekly digest

One DevOps fix in your inbox each week

Short, practical, no fluff. Real errors, real fixes — straight from production postmortems.