You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
terraform/website/docs/language/state/locking.mdx

47 lines
2.2 KiB

---
page_title: 'State: Locking'
description: >-
Terraform stores state which caches the known state of the world the last time
Terraform ran.
---
⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️
> [!IMPORTANT]
> **Documentation Update:** Product documentation previously located in `/website` has moved to the [`hashicorp/web-unified-docs`](https://github.com/hashicorp/web-unified-docs) repository, where all product documentation is now centralized. Please make contributions directly to `web-unified-docs`, since changes to `/website` in this repository will not appear on developer.hashicorp.com.
⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️
# State Locking
If supported by your [backend](/terraform/language/backend), Terraform will lock your
state for all operations that could write state. This prevents
others from acquiring the lock and potentially corrupting your state.
State locking happens automatically on all operations that could write
state. You do not see any message that it happens. If state locking fails,
Terraform does not continue. You can disable state locking for most commands
with the `-lock=false` flag, but we do not recommend it.
If acquiring the lock takes longer than expected, Terraform outputs
a status message. If Terraform does not output a message, state locking is
still occurring if your backend supports it.
Not all backends support locking. The
[documentation for each backend](/terraform/language/backend)
includes details on whether it supports locking or not.
## Force Unlock
Terraform has a [force-unlock command](/terraform/cli/commands/force-unlock)
to manually unlock the state if unlocking failed.
**Be very careful with this command.** If you unlock the state when someone
else is holding the lock it could cause multiple writers. Force unlock should
only be used to unlock your own lock in the situation where automatic
unlocking failed.
To protect you, the `force-unlock` command requires a unique lock ID. Terraform
will output this lock ID if unlocking fails. This lock ID acts as a
[nonce](https://en.wikipedia.org/wiki/Cryptographic_nonce), ensuring
that locks and unlocks target the correct lock.