I’ve got a scenario where I need to ensure that the user hasn’t configured the same value for two different attributes:
resource "foo" "foo" {
attr1 = 50
attr2 = 60
attr3 = 50
attrDifferentFrom1or2or3 = <anything other than 50 or 60 is okay here>
}
These attributes aren’t actually right at the top level of a resource/datasource, but rather in a deeply nested object, so I think I’m looking for an attribute validator.
None of the built-in validators jump out at me as a solution, and right now it’s a bunch of clunky business logic invoked by the resource’s ValidateConfig()
method.
A proper validator seems cleaner, so I’m planning to write a uniqueAmong()
or differentFrom()
validator so I can do:
"attrDifferentFrom1or2or3": schema.Int64Attribute{
Validators: []validator.Int64{
int64validator.DifferentFrom(
path.MatchRelative().AtParent().AtName("attr1"),
path.MatchRelative().AtParent().AtName("attr2"),
path.MatchRelative().AtParent().AtName("attr3"),
),
},
},
Am I on the right track here?
Does this look like it might be useful to others? If so, I can take a crack at the full complement of string/int64/set/list/object validators and submit a PR…