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.
In more detail
It replaces the older DynamoDB-based locking, which is now deprecated. It relies on conditional writes in Amazon S3, so only one run can create the lock file at a time.
Example
backend "s3" {
bucket = "example-tf-state"
key = "orders/terraform.tfstate"
region = "eu-west-2"
use_lockfile = true
}Related terms
- state locking — Preventing two Terraform runs from writing the same state at once, by taking a lock before any operation that could change it.
- Terraform backend — The setting that decides where Terraform stores state and how it locks it, from a local file to shared cloud storage.
- Amazon S3 — Amazon's object storage service, which keeps files, called objects, in containers called buckets.
- Amazon DynamoDB — Amazon's fully managed key-value and document database, which stores items in tables without any servers for you to run.
Taught in
- Continuous IaC Drift Detection & State Protection — Cloud Security & DevSecOps Engineering
- 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 Locking: One Writer At A Time — HashiCorp Terraform Associate (004) Exam Prep