Founding prices until 15 December: 30% off Pro, locked for life. See pricing

$ … Error acquiring the state lock

Terraform 'Error acquiring the state lock': safe ways out

Another run holds the state lock, or a crashed run left it behind.

Terraform

What it means

Terraform and OpenTofu lock the state during plan and apply so two runs can't corrupt it. The error shows who holds the lock and since when. If a run is still going, wait; if one crashed, the lock is stale.

Causes and fixes

Most likely first. Run the check, and if it matches, apply the fix.

1. Another plan or apply is running (a CI job, a colleague)

Check:

Read the Who and Created fields in the error

Fix: Wait for it to finish; add CI concurrency so only one runs per state.

2. A crashed or cancelled run left the lock

Check:

Confirm nothing is running anymore

Fix: terraform force-unlock <LOCK_ID>, only once you're sure.

Fix it yourself

A live machine in your browser with this problem already on it. The grader checks the result.

Open the lab

No account needed for your first tries.

Related errors