validators

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AlsoRequiresOnValues

func AlsoRequiresOnValues(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_attr": schema.StringAttribute{
			Optional: true,
			Validators: []validator.String{
				// Validate other_attr must be configured if this attribute is set to one of ["value1", "value2"].
				AlsoRequiresOnValues(
					[]string{
						"value1",
						"value2",
					},
					path.Expressions{
						path.MatchRoot("other_attr"),
					}...),
			},
		},
		"other_attr": schema.StringAttribute{
			Optional: true,
		},
	},
}
Output:

Types

type AlsoRequiresOnValuesValidator

type AlsoRequiresOnValuesValidator struct {
	OnValues        []string
	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) ValidateString

ValidateString implements validator.String.

Jump to

Keyboard shortcuts

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