Terraform: Error Acquiring the State Lock

terraform plan or apply stops with 'Error acquiring the state lock'. Terraform locks state so two runs can't corrupt it — this means a lock is already held. Here's how to tell if it's real, and how to clear a stale one safely.

BytExplorer 5 min read July 19, 2026

You run terraform plan or apply and it refuses to start:

Error: Error acquiring the state lock

Lock Info:
  ID:        a1b2c3d4-...
  Operation: OperationTypeApply
  Who:       you@laptop
  Created:   2026-07-19 10:30:00

This is a safety feature, not a bug. With a remote backend, Terraform takes a lock on the state before it writes, so two applys can never run at once and corrupt your state. This error means the lock is already held. The only question is: by a real running operation, or a stale one left behind by a crash?

Cause 1: Another run really is in progress

Someone else (or a CI pipeline) is applying right now, or you left a run going in another terminal. This is the lock doing its job. Wait for the other operation to finish — it releases the lock automatically when it's done.

Cause 2: A previous run crashed and left the lock

If a run was killed mid-flight (network drop, Ctrl-C at the wrong moment, a CI runner that died), the lock is never released. The Lock Info block helps you judge: if Who is you, the Created time is old, and you're certain nothing is running, it's stale.

How to clear a stale lock

Terraform gives you the lock ID in the error. Release it explicitly:

terraform force-unlock a1b2c3d4-...

Only force-unlock when you are certain no operation is actually running. Unlocking a live apply is exactly the corruption the lock exists to prevent. When in doubt, wait rather than force.

Prevent it in a team

  • Use a backend that supports locking (S3 with DynamoDB, pg, Terraform Cloud, azurerm, gcs) — plain local or S3-without-DynamoDB doesn't lock.
  • Don't Ctrl-C an apply; let it finish or fail on its own.
  • In CI, make sure only one pipeline touches a given state at a time.

The checklist

  1. The lock is protecting your state — first assume it's legitimate.
  2. Read the Lock Info: who holds it, and how old is it?
  3. Something really running? Wait — the lock releases itself.
  4. Genuinely stale (a crashed run)? terraform force-unlock <ID> — only when sure.

Frequently Asked Questions

What does "Error acquiring the state lock" mean in Terraform? Your backend already holds a lock on the state, so Terraform won't start a second operation that could corrupt it. Either another run is in progress, or a crashed run left the lock behind.

How do I force-unlock Terraform state? Run terraform force-unlock <LOCK_ID> using the ID from the error message. Do this only when you're certain no operation is actually running — force-unlocking a live apply can corrupt your state.

How do I stop the state lock error from happening? Use a locking backend (S3 + DynamoDB, pg, Terraform Cloud, gcs, azurerm), never Ctrl-C a running apply, and make sure only one person or pipeline applies a given state at a time.

Put it into practice

Stop reading, start building

This pairs with a hands-on BytExplorer course — do it on your own machine and actually keep the skill.

More in Troubleshooting