Terraform "Error Acquiring the State Lock": Safe Unlock

Symptom

terraform apply fails with "Error acquiring the state lock" or "state is locked".

Root cause

A previous apply crashed or is still running, leaving the lock held.

Fix, in order

1. Confirm nothing is actually runningps aux | grep terraform # never unlock mid-apply
2. Unlock by the lock ID from the errorterraform force-unlock <LOCK-ID>
3. Avoid the pattern: state locking in CIS3 backend + DynamoDB lock (classic) or native S3 lockfiles

Prevent it coming back

One apply pipeline per state; never run applies from two laptops.

Run it on clean infra

Spinning up a fresh box to reproduce or escape this error?

Managed cloud hosting

Related

Cloud & DevOps tool comparisons · Hardware build guides

NinjaOps publishes free engineering guides. Some outbound links are affiliate links: they cost you nothing and support the site.

Last reviewed 2026-10-02 · NinjaOps SEO grid · DevOps blog