-
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
Custom Validation condition accessing other variables #26229
Comments
I was just about to create this feature request. Faced the same problem as you did @josh-barker. |
I would also like to add accessing locals {
storage_class = ["MULTI_REGIONAL", "REGIONAL", "NEARLINE", "COLDLINE", "ARCHIVE", "STANDARD", "DURABLE_REDUCED_AVAILABILITY"]
} variable "storage_class" {
type = string
default = "STANDARD"
validation {
condition = contains(local.storage_class, var.storage_class)
error_message = "Supported values include: MULTI_REGIONAL, REGIONAL, NEARLINE, COLDLINE, ARCHIVE, STANDARD, DURABLE_REDUCED_AVAILABILITY."
}
} rather than writing again and again variable "storage_class" {
type = string
default = "STANDARD"
validation {
condition = contains(["MULTI_REGIONAL", "REGIONAL", "NEARLINE", "COLDLINE", "ARCHIVE", "STANDARD", "DURABLE_REDUCED_AVAILABILITY"], var.storage_class)
error_message = "Supported values include: MULTI_REGIONAL, REGIONAL, NEARLINE, COLDLINE, ARCHIVE, STANDARD, DURABLE_REDUCED_AVAILABILITY."
}
} |
Is there an update on this? |
The features described in this thread are essential to DRY code. |
Agree with @AswinKakarot that having this (input) variable, validation functionality able to reference local variables would save a lot of duplication of effort and code... especially where validating (input) variable values against an array/list or map of keys and/or values that are defined as local variables and used in multiple places - I've hit this requirement today. This might even be able to extend into using additional, nested resource/module/data output variables as part of the conditions? - Guess there will be some sort of dependency/resolution order to consider, but this sort of functionality might be especially useful if writing modules (obviouslty, wrapping around resources and other modules) and being able to use outputs from those nested resources and modules to validate input into the modules that are wrapping around and/or making use of them - This would prevent/reduce having to make direct/intermediate changes to the wrapper module(s) and allow the output variables to be passed through/up the module dependency chain. |
Mostly duplicate of #25609 so #25609 (comment) is probably the HashiCorp response. The main differentiation I see with this issue is the explicit calling out of allowing the use of locals, which isn't explicitly called out in #25609 but would probably also be solved by the proposed solution |
Hi all, Indeed, this does seem to be effectively a duplicate of #25609, which is now closed with the solution expected to arrive in the forthcoming Terraform v1.9.0 release. Thanks! |
Current Terraform Version
Use-cases
Hi,
We have situations where we want to create validation rules based on the value of of another variable.
For example, backup policies.
Proposal
Allow validation block to access other variables apart from itself.
References
The text was updated successfully, but these errors were encountered: