Documentation ¶
Overview ¶
Package providervalidator provides validators to express relationships between multiple attributes of a provider. For example, checking that multiple attributes are not configured at the same time.
These validators are implemented outside the schema, which may be easier to implement in provider code generation situations or suit provider code preferences differently than those in the schemavalidator package. Those validators start on a starting attribute, where relationships can be expressed as absolute paths to others or relative to the starting attribute.
Index ¶
- func AtLeastOneOf(expressions ...path.Expression) provider.ConfigValidator
- func Conflicting(expressions ...path.Expression) provider.ConfigValidator
- func ExactlyOneOf(expressions ...path.Expression) provider.ConfigValidator
- func RequiredTogether(expressions ...path.Expression) provider.ConfigValidator
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AtLeastOneOf ¶
func AtLeastOneOf(expressions ...path.Expression) provider.ConfigValidator
AtLeastOneOf checks that a set of path.Expression has at least one non-null or unknown value.
Example ¶
package main import ( "github.com/hashicorp/terraform-plugin-framework-validators/providervalidator" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/provider" ) func main() { // Used inside a provider.Provider type ConfigValidators method _ = []provider.ConfigValidator{ // Validate at least one of the schema defined attributes named attr1 // and attr2 has a known, non-null value. providervalidator.AtLeastOneOf( path.MatchRoot("attr1"), path.MatchRoot("attr2"), ), } }
Output:
func Conflicting ¶
func Conflicting(expressions ...path.Expression) provider.ConfigValidator
Conflicting checks that a set of path.Expression, are not configured simultaneously.
Example ¶
package main import ( "github.com/hashicorp/terraform-plugin-framework-validators/providervalidator" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/provider" ) func main() { // Used inside a provider.Provider type ConfigValidators method _ = []provider.ConfigValidator{ // Validate that schema defined attributes named attr1 and attr2 are not // both configured with known, non-null values. providervalidator.Conflicting( path.MatchRoot("attr1"), path.MatchRoot("attr2"), ), } }
Output:
func ExactlyOneOf ¶
func ExactlyOneOf(expressions ...path.Expression) provider.ConfigValidator
ExactlyOneOf checks that a set of path.Expression does not have more than one known value.
Example ¶
package main import ( "github.com/hashicorp/terraform-plugin-framework-validators/providervalidator" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/provider" ) func main() { // Used inside a provider.Provider type ConfigValidators method _ = []provider.ConfigValidator{ // Validate only one of the schema defined attributes named attr1 // and attr2 has a known, non-null value. providervalidator.ExactlyOneOf( path.MatchRoot("attr1"), path.MatchRoot("attr2"), ), } }
Output:
func RequiredTogether ¶
func RequiredTogether(expressions ...path.Expression) provider.ConfigValidator
RequiredTogether checks that a set of path.Expression either has all known or all null values.
Example ¶
package main import ( "github.com/hashicorp/terraform-plugin-framework-validators/providervalidator" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/provider" ) func main() { // Used inside a provider.Provider type ConfigValidators method _ = []provider.ConfigValidator{ // Validate the schema defined attributes named attr1 and attr2 are either // both null or both known values. providervalidator.RequiredTogether( path.MatchRoot("attr1"), path.MatchRoot("attr2"), ), } }
Output:
Types ¶
This section is empty.