state locking
Preventing two Terraform runs from writing the same state at once, by taking a lock before any operation that could change it.
In more detail
Without a lock, two applies can overwrite each other's state and lose track of real resources. Locking is separate from storage: a backend may store state safely yet not lock it unless configured. terraform force-unlock releases a lock left behind by a crashed run, and should be used only when you are sure nobody else is running.
Related terms
- Terraform state — Terraform's record, usually a JSON file called terraform.tfstate, mapping each resource in the configuration to the real object it created.
- Terraform — An infrastructure-as-code tool from HashiCorp that creates and changes cloud resources such as servers, networks and databases from configuration files.
- Terraform backend — The setting that decides where Terraform stores state and how it locks it, from a local file to shared cloud storage.
- use_lockfile — The s3 backend setting, added in Terraform 1.10, that locks state by writing a small lock file next to it in the bucket, with no extra database.
- Amazon DynamoDB — Amazon's fully managed key-value and document database, which stores items in tables without any servers for you to run.
Related guides
Taught in
- Infrastructure as Code (Handover to Terraform) — Cloud Infrastructure & Hyperscaler Architecture
- Continuous IaC Drift Detection & State Protection — Cloud Security & DevSecOps Engineering
- Predicting Changes, Then Applying Them — Infrastructure as Code with Terraform
- The Problem With Local State — Infrastructure as Code with Terraform
- Configuring A Remote Backend — Infrastructure as Code with Terraform
- State Locking With Use Lockfile — Infrastructure as Code with Terraform
- Workspaces For Multiple Environments — Infrastructure as Code with Terraform
- Security: Secrets In State And Ephemeral Values — Infrastructure as Code with Terraform
- State: Terraform's Memory Of What It Built — HashiCorp Terraform Associate (004) Exam Prep
- The Local Backend, And Workspaces On One Machine — HashiCorp Terraform Associate (004) Exam Prep
- State Locking: One Writer At A Time — HashiCorp Terraform Associate (004) Exam Prep
- Inspecting And Repairing State From The CLI — HashiCorp Terraform Associate (004) Exam Prep
- The Full Mock: Sixty Minutes, Eight Areas, One Plan For The Last Week — HashiCorp Terraform Associate (004) Exam Prep