-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
variable validation fails on optional variables #34148
Comments
Hi @Skyriis, Thanks for filing the issue. This appears to only be an instance of #24128, the error is correct that you can't evaluate I'm not sure what you mean by this causing an "NPE" however. Do you have a configuration which causes a panic and stack trace from Terraform? Thanks! |
Here's one way to write that condition with today's Terraform: validation {
condition = var.example.text != null ? length(var.example.test.val) > 0 : true
error_message = "Invalid"
} The conditional operator only evaluates one of its result "arms" depending on the predicate result, so in the above case if (The unchosen "arm" of the conditional is still subject to static checking, but whether the |
Since we have not heard back in a while I'm going to close the issue; updates can be tracked via #24128. If you have any updates regarding the issue, feel free to open a new issue with the requested information. If you have more questions, you can also use the community forum where there are more people ready to help. Thanks! |
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. |
Terraform Version
Terraform Configuration Files
Debug Output
terraform plan error:
This value is null, so it does not have any attributes.
Expected Behavior
The null check of the optional attribute should end the validation successfully
Actual Behavior
It causes an NPE in
length(var.example.test.val) > 0
sincevar.example.test
isnull
Steps to Reproduce
Additional Context
No response
References
No response
The text was updated successfully, but these errors were encountered: