-
Notifications
You must be signed in to change notification settings - Fork 10k
Description
Terraform Version
$ terraform version
Terraform v0.12.7-dev
Terraform Configuration Files
variable "mapping" {
default = {
"a" = ["b", "c"]
}
}
locals {
mapping = [
for x, y in var.mapping : [
for z in y : {
"${z}" = x
}
]
]
}
output "x" {
value = merge(flatten(local.mapping)...)
}
Debug Output
Crash Output
https://gist.github.com/apparentlymart/e1e86b3299c679df1b66d64e2ee86fb5
Expected Behavior
The value for output x
after applying should be:
{
"b" = "a"
"c" = "a"
}
Actual Behavior
Terraform produces an error during the validation walk:
Error: Invalid expanding argument value
on expand-arguments-error.tf line 18, in output "x":
18: value = merge(flatten(local.mapping)...)
The expanding argument (indicated by ...) must be of a tuple, list, or set
type.
Steps to Reproduce
Using the above configuration, run terraform apply
Additional Context
Interestingly, evaluating the same expression in terraform console
works as expected:
$ terraform console
> merge(flatten(local.mapping)...)
{
"b" = "a"
"c" = "a"
}
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 is cty.DynamicVal
, so perhaps that's the root cause; if so, adding cty.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.