Closed mkielar closed 4 years ago
Hi @mkielar! Sorry for this odd behavior, and thanks for the straightforward reproduction case.
I think you've hit the same underlying bug as hashicorp/terraform#24699 here. I believe this is actually an interaction between two different bugs:
...
fails with this error when it's given an argument whose type is not decidable yet. The normal cause of that is when it's a resource output whose type will not be decided until the apply step, but that doesn't apply in your case and so that brings us to the other bug...concat
function seems to be indicating that it cannot predict its result type, and thus triggering the above described behavior.The first of the bugs above applies to both this one and hashicorp/terraform#24699. The second one is unique to this particular issue, though fixing the first one would make the second one less important because it would change from being an error to just producing incomplete type information that could cause downstream validation to be skipped.
I think the fix over in HCL would be to add a new case to the switch
statement that returns this error for if expandVal.Type()
is cty.DynamicPseudoType
, which is what it would return if the type isn't known yet. In that case, the function should immediately return cty.DynamicVal, diags
and not attempt to execute the function yet. That will then allow the initial validation to succeed, so that later on the function call can be attempted again with full type information and produce the actual result.
I think this is the same root cause as #22404, so I'm going to close this only to consolidate the discussion there. Thanks again!
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
Expected Behavior
cidrsubnets
should return a list of 9 subnets.Actual Behavior
Calling
terraform validate
orterraform apply
ends up with error message like this:Steps to Reproduce
terraform validate
terraform apply
also fails.Additional Context
I'm converting a
list
of strings into alist
of numbers. Then, I'mconcat
enating three lists of numbers, so that they make a biggerlist
of numbers. Then I'm passing the longlist
of numbers asnumbits
tocidrsubnets
and expanding it, ascidrsubnets
does not accept the list by itself.If I don't expand it - i.e. i use:
i get following error with
terraform apply
:So it sees it's a tuple, but then refuses to do the expansion. Also, I fund this terraform module: https://github.com/hashicorp/terraform-cidr-subnets/blob/master/main.tf where it follows similar approach, but with variables instead of locals. I tried it, and then it passes validation correctly. Looks like terraform fails to infer type of a local value in some cases (expansion) but it can infer it in other cases (when I don'd attempt expansion it says it's a tuple).
References