Regression: "value must be known" when generate block contains a dependency block
Describe the bug
"Unsuitable value: value must be known" error when using a dependency block in a generate block like this:
generate "gen" {
path = "generated.tf"
if_exists = "overwrite_terragrunt"
contents = <<EOF
%{ if try(dependency.dep.outputs.value, "") != "" }
locals { from_dep = "${dependency.dep.outputs.value}" }
%{ endif }
EOF
}This error only happens when doing terragrunt run --all, it works when running in a single unit without the --all flag.
Same issue as https://github.com/gruntwork-io/terragrunt/issues/4962, but its happening again in v1.1.4 (works in v1.0.8).
Steps To Reproduce
See code snippet at the top, but for full reproduction see the attached zip file which has a script which runs against a simple case in both versions. The error happens before any cloud credentials are needed so there is no setup besides downloading the versions (which the script handles).
Note: This reproduction was generated by AI but reviewed before submission. Below is the extract of the example run to show what you'd see from running it.
using TF engine: /home/example/bin/tofu (OpenTofu v1.12.6)
detected platform: linux_arm64
+ curl -fL -o ./.bin/terragrunt-1.0.8 https://github.com/gruntwork-io/terragrunt/releases/download/v1.0.8/terragrunt_linux_arm64
+ curl -fL -o ./.bin/terragrunt-1.1.4 https://github.com/gruntwork-io/terragrunt/releases/download/v1.1.4/terragrunt_linux_arm64
==================== terragrunt v1.0.8 (./.bin/terragrunt-1.0.8) ====================
+ find . -type d -name .terragrunt-cache -exec rm -rf {} +
+ TG_TF_PATH=/home/example/bin/tofu ./.bin/terragrunt-1.0.8 run --all -- plan
16:52:55.042 INFO - Unit dep
- Unit app
16:52:55.042 INFO [dep] Downloading Terraform configurations from ./module into ./dep/.terragrunt-cache/itePgiz28GC6p-NEu9-Hmqpz_20/3XhcV4Vu9P545W02Fl7HcBQG6iM
16:52:55.053 INFO [dep] tofu: Initializing the backend...
16:52:55.054 INFO [dep] tofu: Initializing provider plugins...
16:52:55.054 INFO [dep] tofu: OpenTofu has been successfully initialized!
16:52:55.054 INFO [dep] tofu:
16:52:55.054 INFO [dep] tofu: You may now begin working with OpenTofu. Try running "tofu plan" to see
16:52:55.054 INFO [dep] tofu: any changes that are required for your infrastructure. All OpenTofu commands
16:52:55.054 INFO [dep] tofu: should now work.
16:52:55.054 INFO [dep] tofu: If you ever set or change modules or backend configuration for OpenTofu,
16:52:55.054 INFO [dep] tofu: rerun this command to reinitialize your working directory. If you forget, other
16:52:55.054 INFO [dep] tofu: commands will detect it and remind you to do so if necessary.
16:52:55.065 STDOUT [dep] tofu: Changes to Outputs:
16:52:55.065 STDOUT [dep] tofu: + value = "hello"
16:52:55.065 STDOUT [dep] tofu: You can apply this plan to save these new output values to the OpenTofu
16:52:55.065 STDOUT [dep] tofu: state, without changing any real infrastructure.
16:52:55.065 STDOUT [dep] tofu:
16:52:55.065 STDOUT [dep] tofu: ─────────────────────────────────────────────────────────────────────────────
16:52:55.065 STDOUT [dep] tofu: Note: You didn't use the -out option to save this plan, so OpenTofu can't
16:52:55.065 STDOUT [dep] tofu: guarantee to take exactly these actions if you run "tofu apply" now.
16:52:55.078 INFO [dep] tofu: Initializing the backend...
16:52:55.078 INFO [dep] tofu: Initializing provider plugins...
16:52:55.078 INFO [dep] tofu: OpenTofu has been successfully initialized!
16:52:55.078 INFO [dep] tofu:
16:52:55.078 INFO [dep] tofu: You may now begin working with OpenTofu. Try running "tofu plan" to see
16:52:55.078 INFO [dep] tofu: any changes that are required for your infrastructure. All OpenTofu commands
16:52:55.078 INFO [dep] tofu: should now work.
16:52:55.078 INFO [dep] tofu: If you ever set or change modules or backend configuration for OpenTofu,
16:52:55.078 INFO [dep] tofu: rerun this command to reinitialize your working directory. If you forget, other
16:52:55.078 INFO [dep] tofu: commands will detect it and remind you to do so if necessary.
16:52:55.089 WARN [app] Config /tmp/tg-generate-dep-bug/dep/terragrunt.hcl is a dependency of /tmp/tg-generate-dep-bug/app/terragrunt.hcl that has no outputs, but mock outputs provided and returning those in dependency output.
16:52:55.089 INFO [app] Downloading Terraform configurations from ./module into ./app/.terragrunt-cache/GRK9msd75roXn9qW7Ot4QphONE0/3XhcV4Vu9P545W02Fl7HcBQG6iM
16:52:55.100 INFO [app] tofu: Initializing the backend...
16:52:55.101 INFO [app] tofu: Initializing provider plugins...
16:52:55.101 INFO [app] tofu: OpenTofu has been successfully initialized!
16:52:55.101 INFO [app] tofu:
16:52:55.101 INFO [app] tofu: You may now begin working with OpenTofu. Try running "tofu plan" to see
16:52:55.101 INFO [app] tofu: any changes that are required for your infrastructure. All OpenTofu commands
16:52:55.101 INFO [app] tofu: should now work.
16:52:55.101 INFO [app] tofu: If you ever set or change modules or backend configuration for OpenTofu,
16:52:55.101 INFO [app] tofu: rerun this command to reinitialize your working directory. If you forget, other
16:52:55.101 INFO [app] tofu: commands will detect it and remind you to do so if necessary.
16:52:55.112 STDOUT [app] tofu: Changes to Outputs:
16:52:55.112 STDOUT [app] tofu: + value = "hello"
16:52:55.112 STDOUT [app] tofu: You can apply this plan to save these new output values to the OpenTofu
16:52:55.112 STDOUT [app] tofu: state, without changing any real infrastructure.
16:52:55.112 STDOUT [app] tofu:
16:52:55.112 STDOUT [app] tofu: ─────────────────────────────────────────────────────────────────────────────
16:52:55.112 STDOUT [app] tofu: Note: You didn't use the -out option to save this plan, so OpenTofu can't
16:52:55.112 STDOUT [app] tofu: guarantee to take exactly these actions if you run "tofu apply" now.
❯❯ Run Summary 2 units 70ms
────────────────────────────
Succeeded 2
---- v1.0.8: PASS (exit 0), full log saved to /tmp/tmp.EeIhFc7wOM ----
==================== terragrunt v1.1.4 (./.bin/terragrunt-1.1.4) ====================
+ find . -type d -name .terragrunt-cache -exec rm -rf {} +
+ TG_TF_PATH=/home/example/bin/tofu ./.bin/terragrunt-1.1.4 run --all -- plan
16:52:55.148 ERROR Error: Unsuitable value type
16:52:55.148 ERROR on /tmp/tg-generate-dep-bug/root.hcl line 9, in generate "gen":
16:52:55.148 ERROR 8: contents = <<EOF
16:52:55.149 ERROR 9: %{ if try(dependency.dep.outputs.value, "") != "" }
16:52:55.149 ERROR 10: locals { from_dep = "${dependency.dep.outputs.value}" }
16:52:55.149 ERROR 11: %{ endif }
16:52:55.149 ERROR 12: EOF
16:52:55.149 ERROR Unsuitable value: value must be known
16:52:55.149 ERROR Error: Unknown variable
16:52:55.149 ERROR on /tmp/tg-generate-dep-bug/app/terragrunt.hcl line 7, in terraform:
16:52:55.149 ERROR 7: source = include.root.locals.module_source
16:52:55.149 ERROR There is no variable named "include".
16:52:55.149 ERROR Error: Unsuitable value type
16:52:55.149 ERROR on /tmp/tg-generate-dep-bug/app/terragrunt.hcl line 7, in terraform:
16:52:55.149 ERROR 7: source = include.root.locals.module_source
16:52:55.149 ERROR Unsuitable value: value must be known
16:52:55.149 INFO TIP (debugging-docs): For help troubleshooting errors, visit https://docs.terragrunt.com/troubleshooting/debugging
16:52:55.149 ERROR /tmp/tg-generate-dep-bug/app/terragrunt.hcl:7,12-19: Unknown variable; There is no variable named "include"., and 1 other diagnostic(s)
---- v1.1.4: FAIL (exit 1), full log saved to /tmp/tmp.12iCAVxJdy ----
v1.0.8 -> PASS
v1.1.4 -> FAIL
16:52:55.149 ERROR Unsuitable value: value must be known
RESULT: regression reproducedExpected behavior
This should not be an error, this syntax has been supported in the past and is very useful for generating provider blocks based on previous module's output.
Must haves
- Steps for reproduction provided.
Nice to haves
- Terminal output
- Screenshots
Versions
- Terragrunt version: 1.1.0+
- OpenTofu/Terraform version: n/a
- Environment details (Ubuntu 20.04, Windows 10, etc.): mac
Source: gruntwork-io/terragrunt