State Locking — Prevents concurrent modifications to the state file.
S3 + DynamoDB:
1terraform {2 backend "s3" {3 bucket = "my-terraform-state"4 key = "prod/terraform.tfstate"5 region = "us-east-1"6 dynamodb_table = "terraform-locks"7 encrypt = true8 }9}
How DynamoDB lock works:
Manual management:
1terraform force-unlock LOCK_ID
Alternatives: Consul, Azure Blob Storage, Terraform Cloud.
Best practice: Always use a remote backend with locking.