Describe state locking
Unlock the complete study guide + 1,040 practice questions across 16 full exams.
Bundled into the existing HashiCorp Certified: Terraform Associate premium course — no separate purchase.
14-day money-back guarantee — no questions asked.
Included in this chapter:
- Why Terraform locks state
- Backends decide whether locking exists
- Controlling the lock: -lock and -lock-timeout
- Recovering a stuck lock with force-unlock
- Exam pattern recognition
State-lock control surface
| Control | -lock=true (default) | -lock-timeout=DURATION | -lock=false | force-unlock LOCK_ID |
|---|---|---|---|---|
| What it does | Acquires the lock, fails fast if it is held | Retries acquisition for the duration, then errors | Skips the lock for the command | Manually releases an existing lock |
| Kind | Default behavior | Flag on plan, apply, and similar | Flag on plan, apply, and similar | Separate command |
| Concurrency safety | Protected | Protected, waits for the holder | Unprotected | Restores locking after a stale lock |
| Typical use | Everyday runs | Overlapping CI or queued runs | Backend lacks locking, or a solo one-off | Clearing a stale lock after a crash |
| Main risk | None | Long wait if the holder is stuck | Concurrent writes corrupt state | Releasing an active lock corrupts state |
Decision tree
Cheat sheet
Unlock with Premium — includes all practice exams and the complete study guide.