Cross attribute validation

How can a validate function access the value of another attribute? I have a complex schema where one option affects the min/max of several other attributes, and need to validate them.

example: if attribute(“some_other_attribute_not_this_one”) == “optionA” { validate this attribute with min/max of 20-50 }
else if attribute(“some_other_attribute_not_this_one”) == “optionB” { validate this attribute with min/max of 100-200 }

Not possible with a ValidateFunc with v2 of the SDK. Another option is to wrap up the validation logic in a function with a signature like func validateResource(d *schema.ResourceData) error and execute this validation in your Create/Update functions.

@paddy This is a good example of something that would be nice to be able to do in v3/terraform-provider-framework.

You can also use CustomizeDiff to get this behavior, but there are a lot of sharp edges and unintended consequences when you go down that route, so make sure to test thoroughly.

But yes, this is a thing we’d like to enable in v3.

Unfortunate, but thanks!

@CyrusJavan if the validation is done during Create/Update functions, that means the validation will not occur in a terraform validate or terraform plan execution, correct?

@brettjacobson That’s correct.