Allow Variable Validation Conditions to Refer to Other Variables #1336
Labels
enhancement
New feature or request
pending-decision
This issue has not been accepted for implementation nor rejected. It's still open to discussion.
OpenTofu Version
Use Cases
I want to be able to have conditional validation on variables - the condition being the value of other variables.
Currently, I'm trying to implement a load balancer (resource "aws_lb") in AWS - the load balancer resource can either be of type "application" or "network". Depending on the load balancer type, there are several required and optional variables that you can pass in. Terraform throws an error if you fail to pass a required variable, but, if you pass in an optional variable to the wrong load balancer type, there isn't much warning.
For the sake of example, an application load balancer can optionally take a list of security groups, but a network load balancer can't. If a developer passes in a list of security groups to an NLB, they may have specified the wrong value for load_balancer_type, or they may be passing variables into the wrong load balancer resource - in either case, I'd like to give a warning to the developer to save them having to go debugging.
This isn't a request that's strictly for AWS load balancers - the pattern of "value X is required if value Y is Z" seems to be fairly common across Terraform plugins.
Attempted Solutions
I tried adding a validation block here:
Error:
Proposal
Just a few prefaces to my proposals:
Implementing such a feature could allow for cyclic dependencies between variables - although, I think that it's at the developer's own risk - like how to package systems in programming languages facilitate cyclic dependencies (but we still all recognize the benefit of having them).
I think that the (bigger) potential issue is causing a significant growth in the dependency graph by creating a complex set of conditional validation rules
References
The text was updated successfully, but these errors were encountered: