Skip to main content
Version: 5.21.0

Unlock Terragrunt State

During execution, Terraform is often configured to acquire a lock on the state during execution, in order to prevent conflicting changes from being made by other Terraform processes. As such, when attempting to run multiple Terraform jobs on the same module simultaneously, one of the jobs will fail. This is expected; however, in some cases, the state lock may not be released after the associated Terraform process ends. This may happen if the process was terminated pre-maturely, or if certain kinds of errors occur during the execution. If this happens, you will see an error like the following:

Error: Error acquiring the state lock
. . .
Lock Info:
ID: 12345678-1234-1234-123456789abcdef01
Path: state-bucket/env:/main-collab/keycloak.tfstate

The Terragrunt wrapper around Terraform can make it somewhat more difficult to identify the exact module with the state lock, so use this line to parse the location of the lock which must be released:

  Path:      state-bucket/env:/main-collab/keycloak.tfstate

In this case, state-bucket is the name of the S3 state bucket (which should be consistent across all modules), main-collab is the name of the Terraform workspace, and keycloak is the name of the module. To release the state, you will run the following commands on a terminal with the AWS IaC repository checked out and with the appropriate AWS credentials:

cd REPO_PATH/infra-iac/
cd modules/keycloak
export TERRAGRUNT_ENV_FILE=/path/to/your/custom/env.hcl # if using one
terragrunt init
terragrunt workspace select main-collab
terragrunt force-unlock 12345678-1234-1234-123456789abcdef01

For additional details on the configuration of the S3 backend, refer to the remote_state block in the Terragrunt definition, which will usually be contained in the env.hcl file.