Skip to content
Commitpedia
Log in Join & edit

Fix: Terraform Error acquiring the state lock

Another run holds the lock on your Terraform state, or a crashed run left it behind. Find out who holds it, wait or stop that run, and only then release a stale lock with force-unlock.

Drafted with AI from official documentation. Scripts were run in a test environment and repository links verified. Awaiting a human check. Did it work for you? Last edited Outdated?

Edit history of Fix: Terraform Error acquiring the state lock: 1 recorded edit
Edit history · 1 edit
Type
Article
Edits
1
Editors
1
First issued
15 Oct 2026
Last edit
15 Oct 2026
Reading
3 min

terraform plan or terraform apply stops before doing anything and prints:

╷
│ Error: Error acquiring the state lock
│
│ Error message: <backend-specific message>
│ Lock Info:
│   ID:        3b1f2a7e-0000-0000-0000-000000000000
│   Path:      example-tfstate/network/prod/terraform.tfstate
│   Operation: OperationTypeApply
│   Who:       admin@ci-runner-1
│   Version:   1.x.y
│   Created:   2026-10-15 08:12:44.123456 +0000 UTC
│   Info:
│
│
│ Terraform acquires a state lock to protect the state from being written
│ by multiple users at the same time. Please resolve the issue above and try
│ again. For most commands, you can disable locking with the "-lock=false"
│ flag, but this is not recommended.
╵

Terraform locks the state for every operation that could write it, so that two runs cannot change the same state at once. This message means it could not get the lock. The Error message line comes from the backend (S3, Azure, PostgreSQL, and so on) and differs between them; the Lock Info block tells you who holds the lock.

Causes, most likely first

  1. Another run is in progress. A colleague or a CI pipeline is running plan or apply on the same state right now. Who and Created tell you who and since when.
  2. A previous run was interrupted. Ctrl+C at the wrong moment, a closed SSH session, a killed CI job or a crash can leave the lock behind. Created is then old and nobody is running anything.
  3. Two pipelines share one state. Overlapping CI jobs for the same project and environment queue up behind each other’s locks.
  4. Backend permissions. If the account may read the state but not create or delete the lock object (or lock table entry), locking fails even though no one else holds it. The backend error message then usually mentions access being denied.

Step 1: decide whether the lock is live

Contact the person or check the pipeline named in Who. If a run is still going, wait for it. In CI, let runs retry for a while instead of failing immediately:

terraform plan -lock-timeout=10m

Step 2: release a stale lock

Warning: removing a lock that another run still holds lets two processes write the state at the same time, which can corrupt it. Use force-unlock only when you are sure the run that took the lock is no longer running: the CI job is finished or cancelled, and no terminal still runs Terraform for this project.

terraform force-unlock 3b1f2a7e-0000-0000-0000-000000000000

Copy the ID exactly from the Lock Info of your error. Terraform asks for confirmation (-force skips the question). The command only removes the lock; it does not change the state or your infrastructure. With OpenTofu the command is tofu force-unlock LOCK_ID.

Step 3: check the state after an interrupted apply

If the stale lock came from an apply that was killed halfway, some resources may have been created or changed without being recorded. Run terraform plan and read it carefully before applying again. Resources that exist but are missing from state show up as “to add”; bring them under management with an import instead of creating duplicates.

What not to do

  • Do not make -lock=false a habit. It hides this error by turning off the very protection that prevents state corruption.
  • Do not delete lock objects or lock table rows by hand in the backend console unless the backend’s documentation tells you to; force-unlock exists for that.
  • If locks pile up because CI runs overlap, fix the pipeline: run only one job per state at a time.

Official documentation

Did this work for you?

No votes yet. Be the first.

If it did not work, the report form below tells the editors what went wrong.

See also

Repos in the wild

History

Every saved edit is kept. The plot on the sleeve draws one line per edit. Open any edit to see exactly what changed.

  1. Dominik +3,658 chars

Report a problem

Something wrong, unsafe or copied? Tell the editors.
What is wrong?