validators

package
v1.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AlsoRequiresOnBoolValues added in v1.0.0

func AlsoRequiresOnBoolValues(onValues []bool, expressions ...path.Expression) validator.Bool
Example
// Used within a Schema method of a DataSource, Provider, or Resource
_ = schema.Schema{
	Attributes: map[string]schema.Attribute{
		"example_bool_attr": schema.BoolAttribute{
			Optional: true,
			Validators: []validator.Bool{
				// Validate other_attr must be configured if this attribute is set to one of [true].
				AlsoRequiresOnBoolValues(
					[]bool{
						true,
					},
					path.Expressions{
						path.MatchRoot("other_attr"),
					}...),
			},
		},
		"other_attr": schema.StringAttribute{
			Optional: true,
		},
	},
}
Output:

func AlsoRequiresOnStringValues added in v1.0.0

func AlsoRequiresOnStringValues(onValues []string, expressions ...path.Expression) validator.String

AlsoRequiresOnValues checks that a set of path.Expression has a non-null value, if the current attribute or block is set to one of the values defined in onValues array.

Relative path.Expression will be resolved using the attribute or block being validated.

Example
// Used within a Schema method of a DataSource, Provider, or Resource
_ = schema.Schema{
	Attributes: map[string]schema.Attribute{
		"example_string_attr": schema.StringAttribute{
			Optional: true,
			Validators: []validator.String{
				// Validate other_attr must be configured if this attribute is set to one of ["value1", "value2"].
				AlsoRequiresOnStringValues(
					[]string{
						"value1",
						"value2",
					},
					path.Expressions{
						path.MatchRoot("other_attr"),
					}...),
			},
		},
		"other_attr": schema.StringAttribute{
			Optional: true,
		},
	},
}
Output:

func AlsoRequiresOneOfOnBoolValues added in v1.0.6

func AlsoRequiresOneOfOnBoolValues(onValues []bool, expressions ...path.Expression) validator.Bool
Example
// Used within a Schema method of a DataSource, Provider, or Resource
_ = schema.Schema{
	Attributes: map[string]schema.Attribute{
		"example_bool_attr": schema.BoolAttribute{
			Optional: true,
			Validators: []validator.Bool{
				// Validate exactly one of other_attr1 and other_attr2 must be configured if this attribute is set to one of [true].
				AlsoRequiresOneOfOnBoolValues(
					[]bool{
						true,
					},
					path.Expressions{
						path.MatchRoot("other_attr1"),
						path.MatchRoot("other_attr2"),
					}...),
			},
		},
		"other_attr1": schema.StringAttribute{
			Optional: true,
		},
		"other_attr2": schema.StringAttribute{
			Optional: true,
		},
	},
}
Output:

func AlsoRequiresOneOfOnStringValues added in v1.0.6

func AlsoRequiresOneOfOnStringValues(onValues []string, expressions ...path.Expression) validator.String

AlsoRequiresOneOfOnValues checks that a set of path.Expression has a non-null value, if the current attribute or block is set to one of the values defined in onValues array.

Relative path.Expression will be resolved using the attribute or block being validated.

Example
// Used within a Schema method of a DataSource, Provider, or Resource
_ = schema.Schema{
	Attributes: map[string]schema.Attribute{
		"example_string_attr": schema.StringAttribute{
			Optional: true,
			Validators: []validator.String{
				// Validate exactly one of other_attr1 and other_attr2 must be configured if this attribute is set to one of ["value1", "value2"].
				AlsoRequiresOneOfOnStringValues(
					[]string{
						"value1",
						"value2",
					},
					path.Expressions{
						path.MatchRoot("other_attr1"),
						path.MatchRoot("other_attr2"),
					}...),
			},
		},
		"other_attr1": schema.StringAttribute{
			Optional: true,
		},
		"other_attr2": schema.StringAttribute{
			Optional: true,
		},
	},
}
Output:

func ConflictsWithOnBoolValues added in v1.0.6

func ConflictsWithOnBoolValues(onValues []bool, expressions ...path.Expression) validator.Bool
Example
// Used within a Schema method of a DataSource, Provider, or Resource
_ = schema.Schema{
	Attributes: map[string]schema.Attribute{
		"example_bool_attr": schema.BoolAttribute{
			Optional: true,
			Validators: []validator.Bool{
				// Validate other_attr cannot be configured if this attribute is set to one of [true].
				ConflictsWithOnBoolValues(
					[]bool{
						true,
					},
					path.Expressions{
						path.MatchRoot("other_attr"),
					}...),
			},
		},
		"other_attr": schema.StringAttribute{
			Optional: true,
		},
	},
}
Output:

func ConflictsWithOnStringValues added in v1.0.6

func ConflictsWithOnStringValues(onValues []string, expressions ...path.Expression) validator.String

ConflictsWithOnValues checks that a set of path.Expression has a non-null value, if the current attribute or block is set to one of the values defined in onValues array.

Relative path.Expression will be resolved using the attribute or block being validated.

Example
// Used within a Schema method of a DataSource, Provider, or Resource
_ = schema.Schema{
	Attributes: map[string]schema.Attribute{
		"example_string_attr": schema.StringAttribute{
			Optional: true,
			Validators: []validator.String{
				// Validate other_attr cannot be configured if this attribute is set to one of ["value1", "value2"].
				ConflictsWithOnStringValues(
					[]string{
						"value1",
						"value2",
					},
					path.Expressions{
						path.MatchRoot("other_attr"),
					}...),
			},
		},
		"other_attr": schema.StringAttribute{
			Optional: true,
		},
	},
}
Output:

Types

type AlsoRequiresOnValuesValidator

type AlsoRequiresOnValuesValidator struct {
	OnStringValues  []string
	OnBoolValues    []bool
	PathExpressions path.Expressions
}

AlsoRequiresOnValuesValidator is the underlying struct implementing AlsoRequiresOnValue.

func (AlsoRequiresOnValuesValidator) Description

Description implements validator.String.

func (AlsoRequiresOnValuesValidator) MarkdownDescription

func (v AlsoRequiresOnValuesValidator) MarkdownDescription(context.Context) string

MarkdownDescription implements validator.String.

func (AlsoRequiresOnValuesValidator) ValidateBool added in v1.0.0

ValidateBool implements validator.Bool.

func (AlsoRequiresOnValuesValidator) ValidateString

ValidateString implements validator.String.

type AlsoRequiresOneOfOnValuesValidator added in v1.0.6

type AlsoRequiresOneOfOnValuesValidator struct {
	OnStringValues  []string
	OnBoolValues    []bool
	PathExpressions path.Expressions
}

AlsoRequiresOneOfOnValuesValidator is the underlying struct implementing AlsoRequiresOnValue.

func (AlsoRequiresOneOfOnValuesValidator) Description added in v1.0.6

Description implements validator.String.

func (AlsoRequiresOneOfOnValuesValidator) MarkdownDescription added in v1.0.6

MarkdownDescription implements validator.String.

func (AlsoRequiresOneOfOnValuesValidator) Validate added in v1.0.6

func (AlsoRequiresOneOfOnValuesValidator) ValidateBool added in v1.0.6

ValidateBool implements validator.Bool.

func (AlsoRequiresOneOfOnValuesValidator) ValidateString added in v1.0.6

ValidateString implements validator.String.

type AlsoRequiresOneOfOnValuesValidatorRequest added in v1.0.6

type AlsoRequiresOneOfOnValuesValidatorRequest struct {
	Config         tfsdk.Config
	ConfigValue    attr.Value
	Path           path.Path
	PathExpression path.Expression
}

type AlsoRequiresOneOfOnValuesValidatorResponse added in v1.0.6

type AlsoRequiresOneOfOnValuesValidatorResponse struct {
	Diagnostics diag.Diagnostics
}

type ConflictsWithOnValuesValidator added in v1.0.6

type ConflictsWithOnValuesValidator struct {
	OnStringValues  []string
	OnBoolValues    []bool
	PathExpressions path.Expressions
}

ConflictsWithOnValuesValidator is the underlying struct implementing AlsoRequiresOnValue.

func (ConflictsWithOnValuesValidator) Description added in v1.0.6

Description implements validator.String.

func (ConflictsWithOnValuesValidator) MarkdownDescription added in v1.0.6

func (v ConflictsWithOnValuesValidator) MarkdownDescription(context.Context) string

MarkdownDescription implements validator.String.

func (ConflictsWithOnValuesValidator) ValidateBool added in v1.0.6

ValidateBool implements validator.Bool.

func (ConflictsWithOnValuesValidator) ValidateString added in v1.0.6

ValidateString implements validator.String.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL