-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Hint about failed conversion to list when returning error about mismatched tuple types in conditional #32301
Comments
Thanks for this report! |
Hi @skeggse! Looking at the expression you wrote in
Because Terraform's attempts to guess what you might have meant and apply implicit type conversions failed, Terraform just fell back on returning the most direct description of the original problem: the conditional expression arms are of different tuple types. While I can use my human intuition to infer from the context what you intended this expression to mean, I'm not sure how to express that as a rule we could write in code to produce the error message you proposed. It would require Terraform to guess that you intended these tuples to be converted to lists and that it's the failure to convert to list that was the problem, not the direct type inconsistency. Being explicit that the conditional result arms are supposed to be lists gives Terraform the extra hint required to get the error message you wanted:
...but without that hint Terraform concludes that you must've intended the results to be tuples, because the automatic conversion to list failed. I agree that what happened here isn't ideal, but I'm not really sure what to do about it. The best idea I have is to extend the error message to explicitly acknowledge the failed attempt at type conversion somehow. For example:
We've run into trouble in the past putting this sort of extra content in error messages because folks who only skim error messages tend to shut off and fail to process the message at all when there's more than one possibility to consider. But perhaps it would be okay in this case, since I'd imagine that intent to convert to a list is the more likely case than trying to select between two different tuple types. (This error message actually belongs to HCL rather than to Terraform, so if we choose to make a change like I described above then we'll need to do it in the HCL repository rather than here.) |
Terraform Version
Terraform Configuration Files
Debug Output
not enabling
TF_LOG
because it's not necessary for this report.Expected Behavior
An error message for
bad_message
explaining that the problem was a missing field:Actual Behavior
The following error message, which, when embedded deep inside a
for_each
clause makes debugging pretty tricky.Steps to Reproduce
terraform init
terraform validate
(orterraform plan
)Additional Context
No response
References
No response
The text was updated successfully, but these errors were encountered: