
Terraform state locking stops two runs from writing the same state at once. That is how Terraform keeps your state consistent. It is also why, as more teams ship to one environment, their deployments line up and wait.
This post covers what the lock does, why splitting one Terraform project into many does not remove the wait, and how parallel releases let changes that do not conflict run at the same time. If you are new to Terraform, start with the beginner's guide to infrastructure as code with Terraform.
What Terraform state locking does
Terraform keeps a state file that maps your configuration to the real resources in your cloud. By default, every command that can write the state, such as plan, apply and destroy, takes a lock on it first. The lock is released when the command finishes.
Remote backends hold the lock for you:
- S3 can keep a lock file next to the state (
use_lockfile = true), so it no longer needs a separate DynamoDB table. - Google Cloud Storage, azurerm and HCP Terraform lock natively.
- Local state uses a lock on the file itself.
When a second run starts while the first one holds the lock, it fails with Error acquiring the state lock. The error shows the lock ID, who holds the lock and when they took it. Two options help:
-lock-timeout=5mmakes the second run wait for the lock instead of failing at once.terraform force-unlock LOCK_IDremoves a lock that a crashed run left behind. Use it only when you are sure that no run still holds the lock. If a run is still writing, you can corrupt the state.
The lock is the right design. Its cost is that every write to one state happens one at a time.
The problem: one state, one queue
Sequential deployments
When many teams and services share one Terraform state, the lock turns their deployments into a queue:
- State locking. Terraform locks the remote state during each operation.
- The queue. If several teams need to deploy at the same time, they wait in line for the lock.
- Lost time. Developers and operations teams wait, and the wait is longest in environments that deploy many times a day.
Example scenario
Team A updates Service X and takes the lock. Team B needs to update Service Y, so it waits until Team A's run finishes. The queue grows with every team that ships. AI coding assistants make it longer, because each engineer now sends more changes every week.
The usual answer is to split Terraform into many smaller projects, each with its own state. That removes the shared lock, but it moves other work onto people.
Why not split the state?
A single Terraform project for each environment keeps four things that split projects lose:
- One dependency graph orders everything. Terraform builds a graph of every resource and applies them in the right order. The database exists before the service that uses it, with no Terragrunt
dependencyblocks or scripts to set the order. - One plan shows the full impact of a change. A change to a shared VPC or load balancer shows up in one plan, next to everything it touches.
- One state per environment is the record. It holds what exists in that environment, so no change falls between two state files.
- Environments differ by inputs, not by copied projects. Development, staging and production run the same configuration with different values and separate state.
Splitting the project gives these up. Each dependency between projects must be declared by hand, and outputs must be passed from one project to the next. For example, a VPC in one project passes its subnets to an application in another, and someone must make sure the VPC is applied first. Tools such as Terragrunt help with this, and they bring their own trade-offs:
- Explicit dependencies. Every dependency between units must be declared, and the list grows with the system.
- No single plan with real values. A unit that reads another unit's outputs cannot show a full plan with real values until that unit is applied.
- Manual recovery. If a dependent unit fails midway, someone fixes it and applies again.
So one project solves the dependency problem and creates the lock problem. Splitting solves the lock problem and gives the dependency problem back to people. The rest of this post is about the first trade: keep one project, and stop the lock from becoming a queue.
How parallel releases break the queue
Facets keeps one model of the system and runs each environment's Terraform with its own state. It does not split the state to avoid the lock. It runs parallel releases instead:
- Releases can be selective. A selective release deploys only the resources you pick.
- Non-conflicting releases run together. With parallel releases on, selective releases in the same environment that do not touch the same resources run at the same time. This covers every resource type.
- Conflicting releases wait. Releases that touch the same resource, or that create or delete shared resources, wait in the queue or fail with a state-lock error. You trigger a failed one again after the conflict clears.
- You set the limit. Parallel releases are off by default. You turn them on in the control plane settings and set the maximum number that may run at once.
From the command line, one selective release looks like this:
raptor create release -p PROJECT -e ENVIRONMENT --target service/api --target postgres/main-dbEach --target names one resource as TYPE/NAME. Add --no-queue to fail at once when another release is already running in the environment, instead of joining the queue.
How it stays safe
Parallel releases do not remove the lock. Releases that touch different resources run side by side, and releases that touch a shared resource still take turns. A release that waits for approval blocks parallel runs until someone approves or rejects it. Rollbacks work as usual, and a release with Refresh may be needed to fully restore the environment after a rollback.
Benefits of parallel releases
- Less waiting. Teams deploy separate services at the same time, without a queue.
- Room to grow. More services do not make the queue longer, as long as they do not share resources.
- Shared infrastructure stays protected. Changes to shared resources still go one at a time.
- A better developer experience. Developers spend less time waiting for a lock and more time on the work.
Adopting scoped locking: key takeaways
If you run Terraform yourself, these steps follow the same idea. Test each one in a non-production environment first.
Plan without a global lock
Generate plans from the remote state with locking turned off (-lock=false), so teams can plan at the same time.
Check the plan's scope
Check that the plan touches only the intended modules, such as the resources of one service, and nothing shared. If the check fails, fall back to a normal run with the lock.
Apply from a local copy of the state, with care
When locks are off, apply from a local copy of the state, so that two runs do not race on the remote state. This is safe only after the scoped plan check passes. If two runs could touch the same resource, keep the lock.
Sync the remote state on a schedule
Bring the remote state up to date in a maintenance window, for example with a refresh-only run (terraform apply -refresh-only).
Keep locks for shared infrastructure
Keep the lock for shared components, such as networks and clusters, and let updates to a single module go ahead on their own.
Conclusion
State locks keep Terraform consistent, and they turn a shared state into a queue. Splitting the state removes the queue and moves the ordering work to people. Parallel releases keep one project and one order, and let changes that do not conflict run at the same time. One model of the whole system is also what people and AI agents need to reason about a change.
This is how Facets makes Terraform work for many teams at once, one of the reasons it builds on the Terraform you know. To see how teams compare Facets with the tools that run Terraform today, read why Terraform automation tools fall short, and for the bigger picture, see infrastructure automation and orchestration.
