
- Exclusive write access to the state
- Automatic creation of the lock table (when using Terragrunt’s
remote_state) - Reliable, distributed coordination across teams and CI/CD environments
Configuring remote_state in Terragrunt
To enable DynamoDB locking, define a remote_state block in your terragrunt.hcl. Terragrunt will create the DynamoDB table if it doesn’t already exist.
Terragrunt automatically provisions the DynamoDB table specified by
dynamodb_table. You only need AWS IAM permissions for S3 and DynamoDB table creation.| Backend Option | Description | Example Value |
|---|---|---|
| bucket | S3 bucket name for state storage | "my-terraform-state-bucket" |
| key | Path within bucket for the .tfstate file | "envs/prod/terraform.tfstate" |
| region | AWS region for both S3 and DynamoDB operations | "us-east-1" |
| encrypt | Enable server-side encryption (SSE) for the file | true |
| dynamodb_table | DynamoDB table name for state locking | "my-terraform-lock-table" |
Handling Stuck Locks
If a Terraform or Terragrunt process crashes mid-run, the DynamoDB lock may remain, blocking subsequent operations. Use the force-unlock command to clear a stuck lock.Forcing an unlock can lead to concurrent modifications if another process is still running. Always verify no other operations are active before using
force-unlock.Benefits of DynamoDB State Locking
| Benefit | Description |
|---|---|
| Single-Writer Enforcement | Prevents multiple users or CI jobs from applying at the same time |
| Automated Table Management | Terragrunt creates and manages the DynamoDB lock table, reducing manual steps |
| Robust CI/CD Integration | Locks persist across distributed pipelines, ensuring consistent state access |
| Safe Recovery from Failures | force-unlock provides a backdoor to unblock state operations |