You run terraform plan or terraform apply and Terraform stops before doing anything:
Error: Error acquiring the state lock
Error message: ConditionalCheckFailedException: The conditional request failed
Lock Info:
ID: 6f1d3c2a-8b0e-4c1d-9a7e-2f5b8c9d0e11
Path: my-tf-state/prod/terraform.tfstate
Operation: OperationTypeApply
Who: jenkins@build-agent-02
Version: 1.9.5
Created: 2026-11-24 06:12:41 UTC
This is Terraform protecting you, not a bug. The fix is to find out whether the lock is active or stale.
What the error means
With a remote backend, Terraform takes a lock on the state file before any operation that could change it. With the S3 backend, the lock is stored in a DynamoDB table (dynamodb_table) or, on Terraform 1.10 and later, as a lock file in the bucket (use_lockfile = true). If a lock already exists, the next run fails with this error.
The Lock Info block tells you who holds the lock (Who), what they were doing (Operation) and when (Created).
How to fix it, step by step
1. Check whether another run is still active
- Look at
Who: is it a teammate or a CI agent? - Check your CI/CD system (Jenkins, GitLab, GitHub Actions, Azure Pipelines) for a running job on the same workspace.
- Check your own terminals for a forgotten
applywaiting at the "Enter a value" prompt. It holds the lock until you answer.
If a run is active, wait for it. Don't unlock.
2. If the lock is stale, force-unlock with the lock ID
A lock becomes stale when a run is killed (cancelled pipeline, closed laptop, crashed agent) before releasing it. Run this from the same configuration directory, with the same backend and workspace:
terraform force-unlock 6f1d3c2a-8b0e-4c1d-9a7e-2f5b8c9d0e11
Terraform asks for confirmation. In automation you can add -force, but prefer doing this manually so a person checks first.
3. Make a run wait instead of failing
If locks are short-lived (two pipelines that overlap by a minute), let Terraform retry:
terraform apply -lock-timeout=5m
4. If force-unlock fails, inspect the lock directly
For a DynamoDB lock table, the lock is an item whose LockID contains the state path. You can view it in the DynamoDB console. Deleting it by hand has the same effect as force-unlock, so apply the same safety check first.
5. After unlocking, verify the state
If the previous run died mid-apply, some resources may have changed. Run a plan and review it carefully before applying again:
terraform plan
How to prevent it
- Never run two pipelines against the same state at once: use
disableConcurrentBuilds()in Jenkins orresource_groupin GitLab CI. Our DevOps training covers these pipeline patterns. - Split large configurations into smaller states per environment or component, so fewer people share one lock.
- Use
-lock-timeoutin CI and avoid interactiveapplyprompts in automation (save a plan file, then apply it). - Never disable locking with
-lock=falseon shared state.
Remote state, locking and team workflows are covered hands-on in our Terraform training for AWS, Azure, GCP and OCI.
Frequently asked questions
Is it safe to run terraform force-unlock?
Yes, but only when you are sure no other Terraform process is using the state. Unlocking while another apply is running can corrupt the state file.
Where do I find the lock ID?
It is printed in the error message under 'Lock Info' as the ID field. Pass exactly that value to terraform force-unlock.
How do I stop pipelines from causing state lock errors?
Prevent concurrent runs on the same state (for example Jenkins disableConcurrentBuilds or GitLab resource_group), and use -lock-timeout so a run waits briefly instead of failing immediately.
Learn Terraform & IaC hands-on with expert trainers
Fixing problems like this one is part of our Terraform & IaC training: live online classes for individuals and on-site corporate training for teams, with real projects and labs.
Training available in Hyderabad, Bangalore, Pune, Mumbai, Delhi, Chennai and online across India.