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?
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
- Another run is in progress. A colleague or a CI pipeline is running plan or apply on the same state right now.
WhoandCreatedtell you who and since when. - 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.
Createdis then old and nobody is running anything. - Two pipelines share one state. Overlapping CI jobs for the same project and environment queue up behind each other’s locks.
- 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=falsea 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-unlockexists 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
- 0187 Terraform concepts: providers, state, plan and apply, modules, and OpenTofu Terraform describes infrastructure in code, compares it with what exists, and changes only the difference. Learn providers, resources, state, the plan/apply loop,… Beginner · Explains an idea · Any system Article Terraform 15 Oct 2026
- 0188 First Terraform configuration: variables, a module and outputs (no cloud needed) A complete Terraform project that writes local files with the hashicorp/local provider, so you can practice init, plan, apply, modules and destroy… Intermediate · Step by step · Any system Script Terraform 15 Oct 2026
- 0189 Terraform remote state: backends, locking and migrating local state Move Terraform state from a local file into a shared backend such as S3 with locking, so a team can work safely.… Advanced · Step by step · Any system Article Terraform 15 Oct 2026
- 0256 Manage infrastructure as code with Terraform: from first file to plans on pull requests Learn the full Terraform workflow without a cloud account: variables, a module, outputs, state, plan, apply and destroy, a backend for shared… Beginner · Guided project · Linux, macOS, Windows Article GitHub Actions · Terraform 15 Oct 2026
Repos in the wild
- OpenTofu: open-source infrastructure as code opentofu/opentofu OpenTofu is the community fork of Terraform under the MPL-2.0 license, run as a Linux Foundation project. It uses the same configuration language and providers. GitHub
History
Every saved edit is kept. The plot on the sleeve draws one line per edit. Open any edit to see exactly what changed.
- Dominik +3,658 chars