-
Notifications
You must be signed in to change notification settings - Fork 9.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Argument expansion error in output expression during validation walk #22404
Comments
Bumped into this. Currently I'm working around this by...
or in this case maybe a double flatten? but a single flatten is actually sufficient for me. |
Bug is still present in
|
Error still present in v0.12.17, can anyone provide a solution or workaround ? locals { Error: Invalid expanding argument value
|
Seeing something similar in 0.12.18. As far as I can tell, the only difference between the two examples is whether the follow data structure comes from a target_groups = {
tg1 = ["api", "www"]
} Workinglocals {
target_groups = {
tg1 = ["api", "www"]
}
tuple_of_maps = [
for target_group, domains in local.target_groups :
{ for domain in domains : domain => target_group }
]
domains = merge(local.tuple_of_maps...)
}
resource "null_resource" "this" {
for_each = local.domains
}
output "resources" {
value = [for nr in null_resource.this : nr.id]
} output:
Not Workingvariable "target_groups" {
default = {
tg1 = ["api", "www"]
}
type = map(list(string))
}
locals {
tuple_of_maps = [
for target_group, domains in var.target_groups :
{ for domain in domains : domain => target_group }
]
domains = merge(local.tuple_of_maps...)
}
resource "null_resource" "this" {
for_each = local.domains
}
output "resources" {
value = [for nr in null_resource.this : nr.id]
} output:
@leoskyrocker's workaround appears to fix my contrived example. |
Huh, looks like I was really tired yesterday when I effectively reposted the original example without recognizing I'd done so 🤦♂ . Could this bug be related to #22576? |
@leoskyrocker You are a savior. I just spent hours trying to figure out was wrong with my expressions. Can confirm this workaround works and saved my sanity. |
terraform 0.12.20 - still not works. The workaround still works (the formula above) |
I believe this should be fixed by hashicorp/hcl#386 once Terraform's HCL dependency is upgraded to a version including that change. |
I'm on version v0.12.26. I don't think the workaround is working for me :'(
|
Passing the list through flatten() does not resolve the issue for me, but passing it through a utility module that calls merge does. I called it merge_list.
|
@web-vertalo @iridian-ks I think, because this is a weird syntax-parsing error, part of the key to the workaround is wrapping your value in a list literal before flattening and merging: |
Ran in to this with Terraform 0.12.28 on Linux x86_64 with the following snippet: locals {
azs = length(data.aws_availability_zones.azs.names)
total_subnets = (var.private_subnets + var.public_subnets)
newbits = [for i in range(local.total_subnets) : ceil(log(local.total_subnets, 2))]
subnet_cidrs = cidrsubnets(var.cidr_block, local.newbits...)
} Changing the last line to subnet_cidrs = cidrsubnets(var.cidr_block, flatten([local.newbits])...) fixes the issue. Also the original code (without |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
Terraform Version
Terraform Configuration Files
Debug Output
Crash Output
https://gist.github.com/apparentlymart/e1e86b3299c679df1b66d64e2ee86fb5
Expected Behavior
The value for output
x
after applying should be:Actual Behavior
Terraform produces an error during the validation walk:
Steps to Reproduce
Using the above configuration, run
terraform apply
Additional Context
Interestingly, evaluating the same expression in
terraform console
works as expected:The console is evaluating expressions in a different mode than in the validate walk, so perhaps there's something unusual about the validate walk that is making this fail.
This bug is likely to be upstream in the HCL repository, e.g. in the
FunctionCallExpr
evaluation logic. It looks like this isn't correctly handling the case where the expression to expand iscty.DynamicVal
, so perhaps that's the root cause; if so, addingcty.DynamicPseudoType
to the set of allowed types is probably enough to fix it, because there's already a test in there for if the value is unknown. If this theory does turn out to be true then this'll be a PR in the HCL repository first, and then a vendor update PR in here.This value would be unknown here during the validation walk because it's derived from a variable, and variables don't get concrete values until the plan walk.
References
This was originally reported in a community forum topic.
The text was updated successfully, but these errors were encountered: