Skip to main content
Error acquiring the state lock

Error acquiring the state lock: Terraform can't lock the state

Terraform stopped before changing anything because it couldn't take the lock on the state. The text after the colon says why.

From HashiCorp's documentation, checked 19 Nov 2026.

Terraform state locking (backend)Statehigh
Error text as HashiCorp documents it
Error: Error locking state: Error acquiring the state lock: <reason> 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.

Also searched as: Error locking state · state lock error · terraform state locked · terraform force-unlock

What it means

Where the backend supports it, Terraform locks the state for every operation that could write it, so two runs can't write the same state at once. If it can't get the lock, it doesn't continue. HashiCorp documents three reasons: another operation holds the lock, an earlier run's automatic unlock failed and left the lock behind, or the state was written by a newer Terraform version than the one you are running.

Common causes

  • Another operation is running against the same state and holds the lock.
  • An earlier run's automatic unlock failed, so its lock is still in place.
  • The state snapshot was created by a newer Terraform version than the one running; the message names the version to upgrade to.
From HashiCorp's documentation

How to fix it

1

Read the reason after the colon

If it says the state snapshot was created by a newer Terraform version, compare it with the version you are running and upgrade to at least the version the message names. Once a newer state file format is in use, there is no supported way back to an older one.

terraform version
2

If another run holds the lock, let it finish

Wait for the other operation to complete, or have Terraform retry for a while before it gives up. The duration is a number and a unit, such as 3s. Don't use -lock=false while others might run commands against the same workspace.

terraform plan -lock-timeout=<duration>
3

Remove your own stuck lock, and only yours

force-unlock is for a lock your own run left behind when automatic unlocking failed. It needs the lock ID Terraform printed when unlocking failed. Unlocking while someone else holds the lock can leave two writers on the same state. It doesn't change your infrastructure.

terraform force-unlock <LOCK_ID>

How to confirm it's fixed

  • Run the command again: it gets past locking and plans or applies without the state lock error.
  • After an upgrade, terraform version reports the version the error asked for, or a later one.

Related notes

Not every backend supports locking; each backend's documentation says whether it does. The S3 backend's locking is opt-in (use_lockfile), and its DynamoDB-based locking is deprecated.

Copyable operational controls

Related engineering templates

Continue the investigation

The KBY Brief

Follow Terraform failures and fixes

A short email about twice a week with new runbooks, configuration traps and fixes from KBY Technologies.