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
conditional fails type unification with nested dynamic values #29809
Comments
Thanks for example @dr-yd! The conditional expressions is working as designed here, because it must find a unified type to return for evaluation, so that both the What's also interesting here is that even when writing out the explicit list comprehension of
to avoid the splat behavior, we still see a single |
Regarding the conditional expression working as designed - as I understand your reply, it should also fail if the value being tested is Even narrowing it down this far took me two hours since I absolutely didn't expect this behavior. And that condition was simple, just As for the rest - thank you for looking into the issue! |
Thanks for the extra info @dr-yd! Optimally the types should unify in the same manner regardless of whether the condition is true or false, so the fact that |
Updating here to show what each step of the process is doing for future work:
The problem with unification in this case is that the expression type needs to be a list due to the possibility of different numbers of values in the container, however the conversion will always fail because while the values each may satisfy the type constraint, the resulting list cannot contain multiple types. There probably cannot be a general solution in the Terraform language until we have inline type conversions to specify the desired types more directly. One improvement which may be possible now within Terraform, is if we can return a more specific type for the resource data accessed during the validate walk. We can determine the mode of expansion from the config, so if we can get an absolute provider and schema, we can get the resource type |
The linked PR #29862 is aiming to handle the case shown here by creating more precisely typed values during validation. This however does not solve the overall problem, since we can't always have exact type information. For example, just switching from a resource to a variable would still produce the same result:
|
I should probably add that in the last example we can make it work by ensuring there is as type for
Which illustrates why I mentioned before that we probably can't solve all these cases until there is a general solution for defining type constraints/conversions inline, since the usual reason why seemingly valid conditional expressions fail to validate is because the inferred types don't match exactly what was intended. |
I think I hit the same problem on terraform 1.1
It works without problem on terraform 1.0.7 In my case environment variable is a
|
Terraform Version
Issue seems to exists in any version after v1.0.4. I finally traced it down with 1.0.9 so please check with that - in previous versions it may behave differently.
Terraform Configuration Files
Debug Output
https://gist.github.com/dr-yd/ac0c838bdac435052865ec21562f716e
Expected Behavior
Actual Behavior
true
, the code is successfully validated.false
, the validation fails as follows:Steps to Reproduce
terraform init
terraform validate
Additional Context
Local CLI, local state.
The text was updated successfully, but these errors were encountered: