-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Describe the bug
When terragrunt is interrupted, like ctrl-c at the 'Do you want to perform these actions?' prompt, the underlying terraform is sent a graceful signal, but the state is left locked. This is notably different behavior than running without terragrunt, where the same action unlocks the state.
It appears that the way terragrunt is interrupt terraform causes terraform to exit more forcefully than when terraform handles the same interrupt
Steps To Reproduce
This is easier to compare behavior between how terragrunt is wrapping terraform and directly running terraform in a unit that has an empty terragrunt.hcl file (that is, loose terraform files that are valid to be run with terraform alone)
- terragrunt apply (in a unit where there is a change)
- at the prompt, press ctrl-c to interrupt
- terragrunt plan
- fails to acquire state lock
for comparison:
- terraform plan (in a unit where there is a change)
- at the prompt, press ctrl-c to interrupt
- terraform plan
- plan is successful
Here is a slightly redacted terminal output:
$ terragrunt apply
11:45:17.500 STDOUT terraform: data.aws_caller_identity.current: Reading...
11:45:17.501 STDOUT terraform: data.aws_region.current: Reading...
<redacted>
11:45:18.047 STDOUT terraform: Terraform used the selected providers to generate the following execution
11:45:18.047 STDOUT terraform: plan. Resource actions are indicated with the following symbols:
11:45:18.047 STDOUT terraform: ~ update in-place
11:45:18.047 STDOUT terraform: Terraform will perform the following actions:
<redacted>
11:45:18.047 STDOUT terraform: Plan: 0 to add, 1 to change, 0 to destroy.
11:45:18.048 STDOUT terraform:
11:45:18.048 STDOUT terraform: Do you want to perform these actions?
11:45:18.048 STDOUT terraform: Terraform will perform the actions described above.
11:45:18.048 STDOUT terraform: Only 'yes' will be accepted to approve.
11:45:18.048 STDOUT terraform: Enter a value:
<ctrl-c pressed here>
11:45:19.845 STDOUT terraform: Interrupt received.
11:45:19.845 INFO Interrupt signal received. Gracefully shutting down...
11:45:19.846 STDOUT terraform: Please wait for Terraform to exit or data loss may occur.
11:45:19.846 STDOUT terraform: Gracefully shutting down...
11:45:19.846 STDERR terraform: ╷
11:45:19.846 STDERR terraform: │ Error: error asking for approval: context canceled
11:45:19.846 STDERR terraform: │
11:45:19.846 STDERR terraform: │
11:45:19.846 STDERR terraform: ╵
11:45:19.867 ERROR terraform invocation failed in .
11:45:19.867 ERROR error occurred:
* Failed to execute "terraform apply" in .
╷
│ Error: error asking for approval: context canceled
│
│
╵
signal: killed
$ terragrunt plan
11:45:24.037 STDERR terraform: ╷
11:45:24.038 STDERR terraform: │ Error: Error acquiring the state lock
11:45:24.038 STDERR terraform: │
11:45:24.038 STDERR terraform: │ Error message: operation error DynamoDB: PutItem, https response error
11:45:24.038 STDERR terraform: │ StatusCode: 400, RequestID:
Here is with TF_LOG=debug terragrunt apply
around the interrupt:
12:06:41.502 STDOUT terraform: Do you want to perform these actions?
12:06:41.502 STDOUT terraform: Terraform will perform the actions described above.
12:06:41.502 STDOUT terraform: Only 'yes' will be accepted to approve.
12:06:41.502 STDOUT terraform: Enter a value:
12:06:43.165 STDOUT terraform: Interrupt received.
12:06:43.165 STDOUT terraform: Please wait for Terraform to exit or data loss may occur.
12:06:43.165 INFO Interrupt signal received. Gracefully shutting down...
12:06:43.166 STDERR terraform: ╷
12:06:43.166 STDOUT terraform: Gracefully shutting down...
12:06:43.166 STDERR terraform: │ Error: error asking for approval: interrupted
12:06:43.166 STDERR terraform: │
12:06:43.166 STDERR terraform: │
12:06:43.166 STDERR terraform: ╵
12:06:43.166 INFO terraform: TF_LOG: backend-s3: Attempting to unlock remote state (DynamoDB only)...: <redacted>
12:06:43.241 ERROR terraform invocation failed in .
12:06:43.244 ERROR error occurred:
<the entire debug log is repeated>
2025-09-15T12:06:41.501-0400 [DEBUG] command: asking for input: "\nDo you want to perform these actions?"
╷
│ Error: error asking for approval: interrupted
│
│
╵
2025-09-15T12:06:43.166-0400 [INFO] backend-s3: Attempting to unlock remote state (DynamoDB only)...: <redacted>
signal: killed
Here is with TF_LOG=debug terraform apply
around the interrupt:
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: ^C
Interrupt received.
Please wait for Terraform to exit or data loss may occur.
Gracefully shutting down...
╷
│ Error: error asking for approval: context canceled
│
│
╵
2025-09-15T12:05:34.934-0400 [INFO] backend-s3: Attempting to unlock remote state (DynamoDB only)...: <redacted>
2025-09-15T12:05:34.935-0400 [DEBUG] backend-s3: HTTP Request Sent: <redacted GetItem>
2025-09-15T12:05:34.957-0400 [DEBUG] backend-s3: HTTP Response Received: <redacted GetItem>
2025-09-15T12:05:34.958-0400 [DEBUG] backend-s3: HTTP Request Sent: <redacted DeleteItem>
2025-09-15T12:05:34.982-0400 [DEBUG] backend-s3: HTTP Response Received: <redacted DeleteItem>
2025-09-15T12:05:34.982-0400 [INFO] backend-s3: Unlocked remote state (DynamoDB only): <redacted>
Expected behavior
When terragrunt triggers an interrupt to terraform it should have the same behavior if terraform itself was interrupted.
Versions
- Terragrunt version: 0.87.2
- OpenTofu/Terraform version: 1.13.2 / hashicorp/aws v6.13.0, also tested opentofu 1.10.6
- Environment details (Ubuntu 20.04, Windows 10, etc.): Debian 13 via WSL, also tested on Windows 11, macOS