Defining relationships between schema attributes, is there a better way?

For a little background, I work on a Terraform provider for work. Often I will define a schema that contains two attributes that have some boolean logic association between them. For example, a resource may require authentication via Password OR Private Key, at least one should be set but not both. Right now I just write the logic into my create and update functions to check the validity of the user input. Is there a better more declarative way to define these types of relationships provided in the SDK?

Hi @CyrusJavan,

I think what you are describing is one of the use-cases that motivated the introduction of the new schema.Schema fields ConflictsWith, ExactlyOneOf, AtLeastOneOf, and RequiredWith. Some of these were added quite recently, so you may need to upgrade to a newer SDK release to use them.

Unfortunately I don’t have a ready example to share because I’ve not yet had an opportunity to try these features myself, but hopefully the documentation is descriptive enough to give you a sense of how to use them. If not, please reply with other questions and hopefully someone with more familiarity will be able to answer!

ExactlyOneOf fits my situation perfectly. Thanks!