-
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
Validation block should allow validation of list of values #24223
Comments
@avarmaavarma - I believe my feature proposal in #24269 would meet these requirements, essentially adding a Would this meet your need?
|
Yes - that should work for what I was looking for. Also, is there a limit on the number of raises...? Can I raise more than once (provided I do so in a separate block?) |
@avarmaavarma - Thanks for confirming. This is still just a proposal - but in terms of number of raises, I can't say for sure and it would likely depend on the implementation. That said, at least in theory, the same rules of error handling could/would apply as with the rest of terraform, specifically that multiple errors are reported when not directly dependent upon each other. As the dependency DAG is resolved, obviously anything downstream from a failed validation check would not be executed. (Samples below.) In theory, I expect that this code would produce two separate errors since both "Calc A" and "Calc B" can be reached, and they both raise an error: locals {
my_int = "asdf"
my_calc_a = try(local.my_int * 5, raise("Can't perform calc A. Is the int really an int?")
my_calc_b = try(local.my_int / 5, raise("Can't perform calc B. Is the int really an int?")
} While this would produce a single error on "Calc A": locals {
my_int = "asdf"
my_calc_a = try(local.my_int * 5, raise("Can't perform calc A. Is the int really an int?")
my_calc_c = try(local.my_calc_a * 5, raise("Can't perform calc C. Is the int really an int?")
} Because Calc C depends on an already failed value ("Calc A"), there's no way to execute it and it would not report an error. |
It is a bit clumsy, but using for expression should work:
Of course more complex validations are possible. |
The parallel effort I am covering in the |
Potentially resolved by: #25088 (PR waiting feedback, CI tests passing) (Alternate validation strategy using |
I've found a quite nice one liner Workaround to validate
The Seems to be easily adaptable to your case as:
Not tested that way and interested to listen if this worked for you. |
This validation block works for a single input variable.
This does not work for a collection of values. The issue is that there is a restriction on the condition statement - the condition only accepts the input variable itself (i.e. - it cannot accept an each.value)
The text was updated successfully, but these errors were encountered: