-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Describe the bug
When using the filter flag like terragrunt --experiment=filter-flag plan --filter="[HEAD~1...HEAD]" --all outputs of already applied dependency units aren't detected and instead the mock outputs are used.
Applying just the changed unit directly like --filter="dependent" without using Git refs works fine, i.e., the already applied dependency unit's outputs are detected and used.
Steps To Reproduce
// modules/dependency/main.tf
output "test_output" {
value = "actual_output"
}// modules/dependent/main.tf
variable "test_input" {
type = string
}
resource "null_resource" "echo" {
for_each = tomap({ (var.test_input) = var.test_input })
provisioner "local-exec" {
command = "echo '${each.key}'"
}
}// units/dependency/terragrunt.hcl
include "root" {
path = find_in_parent_folders("root.hcl")
}
terraform {
source = "${find_in_parent_folders("modules")}/dependency"
}// units/dependent/terragrunt.hcl
include "root" {
path = find_in_parent_folders("root.hcl")
}
terraform {
source = "${find_in_parent_folders("modules")}/dependent"
}
dependency "dependency" {
config_path = "../dependency"
mock_outputs = {
test_output = "mock_output"
}
}
inputs = {
test_input = dependency.dependency.outputs.test_output
}// stacks/root.hcl
remote_state {
backend = "local"
config = {
path = "${get_parent_terragrunt_dir()}/.state/${path_relative_to_include()}/terraform.tfstate"
}
generate = {
path = "backend.tf"
if_exists = "overwrite_terragrunt"
}
}// stacks/test/terragrunt.stack.hcl
unit "dependency" {
source = "${find_in_parent_folders("units")}/dependency"
path = "dependency"
}$ git init
$ git add .
$ git commit -m 'initial commit'
$ cd stacks
$ terragrunt apply --all
13:30:00.581 INFO Generating unit dependency from ./test/terragrunt.stack.hcl
13:30:00.585 INFO Unit queue will be processed for apply in this order:
- Unit test/.terragrunt-stack/dependency
Are you sure you want to run 'terragrunt apply' in each unit of the run queue displayed above? (y/n) y
13:30:01.759 INFO [test/.terragrunt-stack/dependency] Downloading Terraform configurations from ../modules/dependency into ./test/.terragrunt-stack/dependency/.terragrunt-cache/9VwxB0LsvyL1V3lDIwI9ntEaav8/DwmkUDhOVSsWXewKJNfHGLZLrb4
13:30:01.810 INFO [test/.terragrunt-stack/dependency] tofu: Initializing the backend...
13:30:01.813 INFO [test/.terragrunt-stack/dependency] tofu: Initializing provider plugins...
13:30:01.813 INFO [test/.terragrunt-stack/dependency] tofu: OpenTofu has been successfully initialized!
13:30:01.813 INFO [test/.terragrunt-stack/dependency] tofu:
13:30:01.813 INFO [test/.terragrunt-stack/dependency] tofu: You may now begin working with OpenTofu. Try running "tofu plan" to see
13:30:01.813 INFO [test/.terragrunt-stack/dependency] tofu: any changes that are required for your infrastructure. All OpenTofu commands
13:30:01.813 INFO [test/.terragrunt-stack/dependency] tofu: should now work.
13:30:01.813 INFO [test/.terragrunt-stack/dependency] tofu: If you ever set or change modules or backend configuration for OpenTofu,
13:30:01.813 INFO [test/.terragrunt-stack/dependency] tofu: rerun this command to reinitialize your working directory. If you forget, other
13:30:01.813 INFO [test/.terragrunt-stack/dependency] tofu: commands will detect it and remind you to do so if necessary.
13:30:01.872 STDOUT [test/.terragrunt-stack/dependency] tofu: Changes to Outputs:
13:30:01.872 STDOUT [test/.terragrunt-stack/dependency] tofu: + test_output = "actual_output"
13:30:01.872 STDOUT [test/.terragrunt-stack/dependency] tofu: You can apply this plan to save these new output values to the OpenTofu
13:30:01.872 STDOUT [test/.terragrunt-stack/dependency] tofu: state, without changing any real infrastructure.
13:30:01.874 STDOUT [test/.terragrunt-stack/dependency] tofu:
13:30:01.874 STDOUT [test/.terragrunt-stack/dependency] tofu: Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
13:30:01.874 STDOUT [test/.terragrunt-stack/dependency] tofu:
13:30:01.874 STDOUT [test/.terragrunt-stack/dependency] tofu: Outputs:
13:30:01.874 STDOUT [test/.terragrunt-stack/dependency] tofu: test_output = "actual_output"
Now add the dependent unit:
// stacks/test/terragrunt.stack.hcl
unit "dependency" {
source = "${find_in_parent_folders("units")}/dependency"
path = "dependency"
}
unit "dependent" {
source = "${find_in_parent_folders("units")}/dependent"
path = "dependent"
}
git add .
git commit -m 'add dependent unit'
$ terragrunt --experiment=filter-flag plan --filter="[HEAD~1...HEAD]" --all
13:31:28.352 INFO Generating unit dependent from /tmp/terragrunt-worktree-HEAD-856930344/stacks/test/terragrunt.stack.hcl
13:31:28.352 INFO Generating unit dependency from ./test/terragrunt.stack.hcl
13:31:28.352 INFO Generating unit dependency from /tmp/terragrunt-worktree-HEAD-856930344/stacks/test/terragrunt.stack.hcl
13:31:28.352 INFO Generating unit dependency from /tmp/terragrunt-worktree-HEAD_1-3379350842/stacks/test/terragrunt.stack.hcl
13:31:28.352 INFO Generating unit dependent from ./test/terragrunt.stack.hcl
13:31:28.405 INFO Unit queue will be processed for plan in this order:
- Unit stacks/test/.terragrunt-stack/dependent
13:31:28.464 INFO [/tmp/terragrunt-worktree-HEAD-856930344/stacks/test/.terragrunt-stack/dependency] Downloading Terraform configurations from /tmp/terragrunt-worktree-HEAD-856930344/modules/dependency into /tmp/terragrunt-worktree-HEAD-856930344/stacks/test/.terragrunt-stack/dependency/.terragrunt-cache/BdNKsXEZb5ujffbRTD3hSq6ehT0/PTqHdvF9VzAsgxrLwGqFHnRwFx8
13:31:28.516 INFO [/tmp/terragrunt-worktree-HEAD-856930344/stacks/test/.terragrunt-stack/dependency] tofu: Initializing the backend...
13:31:28.519 INFO [/tmp/terragrunt-worktree-HEAD-856930344/stacks/test/.terragrunt-stack/dependency] tofu: Initializing provider plugins...
13:31:28.519 INFO [/tmp/terragrunt-worktree-HEAD-856930344/stacks/test/.terragrunt-stack/dependency] tofu: OpenTofu has been successfully initialized!
13:31:28.519 INFO [/tmp/terragrunt-worktree-HEAD-856930344/stacks/test/.terragrunt-stack/dependency] tofu:
13:31:28.519 INFO [/tmp/terragrunt-worktree-HEAD-856930344/stacks/test/.terragrunt-stack/dependency] tofu: You may now begin working with OpenTofu. Try running "tofu plan" to see
13:31:28.519 INFO [/tmp/terragrunt-worktree-HEAD-856930344/stacks/test/.terragrunt-stack/dependency] tofu: any changes that are required for your infrastructure. All OpenTofu commands
13:31:28.519 INFO [/tmp/terragrunt-worktree-HEAD-856930344/stacks/test/.terragrunt-stack/dependency] tofu: should now work.
13:31:28.519 INFO [/tmp/terragrunt-worktree-HEAD-856930344/stacks/test/.terragrunt-stack/dependency] tofu: If you ever set or change modules or backend configuration for OpenTofu,
13:31:28.519 INFO [/tmp/terragrunt-worktree-HEAD-856930344/stacks/test/.terragrunt-stack/dependency] tofu: rerun this command to reinitialize your working directory. If you forget, other
13:31:28.519 INFO [/tmp/terragrunt-worktree-HEAD-856930344/stacks/test/.terragrunt-stack/dependency] tofu: commands will detect it and remind you to do so if necessary.
13:31:28.580 WARN [stacks/test/.terragrunt-stack/dependent] Config /tmp/terragrunt-worktree-HEAD-856930344/stacks/test/.terragrunt-stack/dependency/terragrunt.hcl is a dependency of /tmp/terragrunt-worktree-HEAD-856930344/stacks/test/.terragrunt-stack/dependent/terragrunt.hcl that has no outputs, but mock outputs provided and returning those in dependency output.
13:31:28.581 INFO [stacks/test/.terragrunt-stack/dependent] Downloading Terraform configurations from /tmp/terragrunt-worktree-HEAD-856930344/modules/dependent into /tmp/terragrunt-worktree-HEAD-856930344/stacks/test/.terragrunt-stack/dependent/.terragrunt-cache/iphAX9Mw-kasr0DubbrO3kX69wg/11C1Ewc9XzjthK26Br374jeQsew
13:31:28.633 INFO [/tmp/terragrunt-worktree-HEAD-856930344/stacks/test/.terragrunt-stack/dependent] tofu: Initializing the backend...
13:31:28.635 INFO [/tmp/terragrunt-worktree-HEAD-856930344/stacks/test/.terragrunt-stack/dependent] tofu: Initializing provider plugins...
13:31:28.635 INFO [/tmp/terragrunt-worktree-HEAD-856930344/stacks/test/.terragrunt-stack/dependent] tofu: - Reusing previous version of hashicorp/null from the dependency lock file
13:31:28.762 INFO [/tmp/terragrunt-worktree-HEAD-856930344/stacks/test/.terragrunt-stack/dependent] tofu: - Detected previously-installed hashicorp/null v3.2.4 in the shared cache directory
13:31:28.763 INFO [/tmp/terragrunt-worktree-HEAD-856930344/stacks/test/.terragrunt-stack/dependent] tofu: - Using hashicorp/null v3.2.4 from the shared cache directory
13:31:28.763 INFO [/tmp/terragrunt-worktree-HEAD-856930344/stacks/test/.terragrunt-stack/dependent] tofu: OpenTofu has been successfully initialized!
13:31:28.763 INFO [/tmp/terragrunt-worktree-HEAD-856930344/stacks/test/.terragrunt-stack/dependent] tofu:
13:31:28.763 INFO [/tmp/terragrunt-worktree-HEAD-856930344/stacks/test/.terragrunt-stack/dependent] tofu: You may now begin working with OpenTofu. Try running "tofu plan" to see
13:31:28.763 INFO [/tmp/terragrunt-worktree-HEAD-856930344/stacks/test/.terragrunt-stack/dependent] tofu: any changes that are required for your infrastructure. All OpenTofu commands
13:31:28.763 INFO [/tmp/terragrunt-worktree-HEAD-856930344/stacks/test/.terragrunt-stack/dependent] tofu: should now work.
13:31:28.764 INFO [/tmp/terragrunt-worktree-HEAD-856930344/stacks/test/.terragrunt-stack/dependent] tofu: If you ever set or change modules or backend configuration for OpenTofu,
13:31:28.764 INFO [/tmp/terragrunt-worktree-HEAD-856930344/stacks/test/.terragrunt-stack/dependent] tofu: rerun this command to reinitialize your working directory. If you forget, other
13:31:28.764 INFO [/tmp/terragrunt-worktree-HEAD-856930344/stacks/test/.terragrunt-stack/dependent] tofu: commands will detect it and remind you to do so if necessary.
13:31:29.102 STDOUT [stacks/test/.terragrunt-stack/dependent] tofu: OpenTofu used the selected providers to generate the following execution
13:31:29.103 STDOUT [stacks/test/.terragrunt-stack/dependent] tofu: plan. Resource actions are indicated with the following symbols:
13:31:29.103 STDOUT [stacks/test/.terragrunt-stack/dependent] tofu: + create
13:31:29.103 STDOUT [stacks/test/.terragrunt-stack/dependent] tofu: OpenTofu will perform the following actions:
13:31:29.103 STDOUT [stacks/test/.terragrunt-stack/dependent] tofu: # null_resource.echo["mock_output"] will be created
13:31:29.103 STDOUT [stacks/test/.terragrunt-stack/dependent] tofu: + resource "null_resource" "echo" {
13:31:29.103 STDOUT [stacks/test/.terragrunt-stack/dependent] tofu: + id = (known after apply)
13:31:29.103 STDOUT [stacks/test/.terragrunt-stack/dependent] tofu: }
13:31:29.103 STDOUT [stacks/test/.terragrunt-stack/dependent] tofu: Plan: 1 to add, 0 to change, 0 to destroy.
13:31:29.103 STDOUT [stacks/test/.terragrunt-stack/dependent] tofu:
13:31:29.103 STDOUT [stacks/test/.terragrunt-stack/dependent] tofu: ─────────────────────────────────────────────────────────────────────────────
13:31:29.103 STDOUT [stacks/test/.terragrunt-stack/dependent] tofu: Note: You didn't use the -out option to save this plan, so OpenTofu can't
13:31:29.103 STDOUT [stacks/test/.terragrunt-stack/dependent] tofu: guarantee to take exactly these actions if you run "tofu apply" now.
❯❯ Run Summary 1 units 704ms
────────────────────────────
Succeeded 1
Note the mock output being used instead of the already applied dependency unit's output actual_output:
# null_resource.echo["mock_output"] will be created
Expected behavior
I'd expect --filter="[HEAD~1...HEAD]" to detect outputs and to work exactly the same as filtering the changed unit directly with --filter="dependent":
terragrunt --experiment=filter-flag plan --filter="dependent" --all
13:45:53.538 INFO Generating unit dependent from ./test/terragrunt.stack.hcl
13:45:53.538 INFO Generating unit dependency from ./test/terragrunt.stack.hcl
13:45:53.590 INFO Unit queue will be processed for plan in this order:
- Unit test/.terragrunt-stack/dependent
13:45:53.698 INFO [test/.terragrunt-stack/dependency] tofu: Initializing the backend...
13:45:53.700 INFO [test/.terragrunt-stack/dependency] tofu: Initializing provider plugins...
13:45:53.700 INFO [test/.terragrunt-stack/dependency] tofu: OpenTofu has been successfully initialized!
13:45:53.701 INFO [test/.terragrunt-stack/dependency] tofu:
13:45:53.701 INFO [test/.terragrunt-stack/dependency] tofu: You may now begin working with OpenTofu. Try running "tofu plan" to see
13:45:53.701 INFO [test/.terragrunt-stack/dependency] tofu: any changes that are required for your infrastructure. All OpenTofu commands
13:45:53.701 INFO [test/.terragrunt-stack/dependency] tofu: should now work.
13:45:53.701 INFO [test/.terragrunt-stack/dependency] tofu: If you ever set or change modules or backend configuration for OpenTofu,
13:45:53.701 INFO [test/.terragrunt-stack/dependency] tofu: rerun this command to reinitialize your working directory. If you forget, other
13:45:53.701 INFO [test/.terragrunt-stack/dependency] tofu: commands will detect it and remind you to do so if necessary.
13:45:54.100 STDOUT [test/.terragrunt-stack/dependent] tofu: OpenTofu used the selected providers to generate the following execution
13:45:54.100 STDOUT [test/.terragrunt-stack/dependent] tofu: plan. Resource actions are indicated with the following symbols:
13:45:54.100 STDOUT [test/.terragrunt-stack/dependent] tofu: + create
13:45:54.100 STDOUT [test/.terragrunt-stack/dependent] tofu: OpenTofu will perform the following actions:
13:45:54.100 STDOUT [test/.terragrunt-stack/dependent] tofu: # null_resource.echo["actual_output"] will be created
13:45:54.100 STDOUT [test/.terragrunt-stack/dependent] tofu: + resource "null_resource" "echo" {
13:45:54.100 STDOUT [test/.terragrunt-stack/dependent] tofu: + id = (known after apply)
13:45:54.100 STDOUT [test/.terragrunt-stack/dependent] tofu: }
13:45:54.100 STDOUT [test/.terragrunt-stack/dependent] tofu: Plan: 1 to add, 0 to change, 0 to destroy.
13:45:54.100 STDOUT [test/.terragrunt-stack/dependent] tofu:
13:45:54.100 STDOUT [test/.terragrunt-stack/dependent] tofu: ─────────────────────────────────────────────────────────────────────────────
13:45:54.100 STDOUT [test/.terragrunt-stack/dependent] tofu: Note: You didn't use the -out option to save this plan, so OpenTofu can't
13:45:54.101 STDOUT [test/.terragrunt-stack/dependent] tofu: guarantee to take exactly these actions if you run "tofu apply" now.
❯❯ Run Summary 1 units 517ms
────────────────────────────
Succeeded 1
Note that the correct output actual_output is used:
# null_resource.echo["actual_output"] will be created
Must haves
- Steps for reproduction provided.
Nice to haves
- Terminal output
- Screenshots
Versions
- Terragrunt version: v0.95.1
- OpenTofu/Terraform version: OpenTofu v1.10.7 on linux_amd64
- Environment details (Ubuntu 20.04, Windows 10, etc.): Ubuntu 24.04.3 LTS
Additional context
This is the issue I mentioned in #4060 (comment) .