terraform { backend "s3" { bucket = "acme-terraform-state" key = "prod/network/terraform.tfstate" # ← your isolation strategy lives here region = "us-east-1" encrypt = true use_lockfile = true # S3-native locking (TF ≥1.10) } }
dynamodb_table for locking.
That's the old way — Terraform 1.10 introduced S3-native locking via
use_lockfile = true (S3 conditional writes create a .tflock object),
and the DynamoDB arguments are deprecated since 1.11. New projects: lockfile only.
Migrating: you can set both during transition, then drop DynamoDB.
Source: S3 backend reference
terraform {} block and activated at terraform init — it is not stored in state, and changing it requires re-init.terraform init -migrate-state (Terraform offers to copy it).terraform init -reconfigure.key is just an object path — one state file per key. Different components/environments use different keys (or different buckets). This is the seed of project structure.| Command / flag | Use when |
|---|---|
-lock-timeout=5m | Instead of failing instantly on a held lock, wait up to N for it to free (CI queues). |
terraform force-unlock LOCK_ID | A crashed run left a stale lock. Verify no run is actually active, then unlock with the ID from the error message. |
-lock=false | Almost never. Disables locking for one operation — a footgun kept for emergencies. |
encrypt = trueuse_lockfile = true in every backend block