A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator below:

setvalidator package - github.com/hashicorp/terraform-plugin-framework-validators/setvalidator - Go Packages

Package setvalidator provides validators for types.Set attributes and function parameters.

This section is empty.

This section is empty.

All returns a validator which ensures that any configured attribute value attribute value validates against all the given validators.

Use of All is only necessary when used in conjunction with Any or AnyWithAllWarnings as the Validators field automatically applies a logical AND.

package main

import (
	"github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
	"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
	"github.com/hashicorp/terraform-plugin-framework/schema/validator"
	"github.com/hashicorp/terraform-plugin-framework/types"
)

func main() {
	// Used within a Schema method of a DataSource, Provider, or Resource
	_ = schema.Schema{
		Attributes: map[string]schema.Attribute{
			"example_attr": schema.SetAttribute{
				ElementType: types.StringType,
				Required:    true,
				Validators: []validator.Set{
					// Validate this Set value must either be:
					//  - More than 5 elements
					//  - At least 2 elements, but not more than 3 elements
					setvalidator.Any(
						setvalidator.SizeAtLeast(5),
						setvalidator.All(
							setvalidator.SizeAtLeast(2),
							setvalidator.SizeAtMost(3),
						),
					),
				},
			},
		},
	}
}

AlsoRequires checks that a set of path.Expression has a non-null value, if the current attribute or block also has a non-null value.

This implements the validation logic declaratively within the schema. Refer to [datasourcevalidator.RequiredTogether], [providervalidator.RequiredTogether], or [resourcevalidator.RequiredTogether] for declaring this type of validation outside the schema definition.

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

package main

import (
	"github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
	"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
	"github.com/hashicorp/terraform-plugin-framework/path"
	"github.com/hashicorp/terraform-plugin-framework/schema/validator"
	"github.com/hashicorp/terraform-plugin-framework/types"
)

func main() {
	// Used within a Schema method of a DataSource, Provider, or Resource
	_ = schema.Schema{
		Attributes: map[string]schema.Attribute{
			"example_attr": schema.SetAttribute{
				ElementType: types.StringType,
				Optional:    true,
				Validators: []validator.Set{
					// Validate this attribute must be configured with other_attr.
					setvalidator.AlsoRequires(path.Expressions{
						path.MatchRoot("other_attr"),
					}...),
				},
			},
			"other_attr": schema.StringAttribute{
				Optional: true,
			},
		},
	}
}

Any returns a validator which ensures that any configured attribute value passes at least one of the given validators.

To prevent practitioner confusion should non-passing validators have conflicting logic, only warnings from the passing validator are returned. Use AnyWithAllWarnings() to return warnings from non-passing validators as well.

package main

import (
	"github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
	"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
	"github.com/hashicorp/terraform-plugin-framework/schema/validator"
)

func main() {
	// Used within a Schema method of a DataSource, Provider, or Resource
	_ = schema.Schema{
		Attributes: map[string]schema.Attribute{
			"example_attr": schema.SetAttribute{
				Required: true,
				Validators: []validator.Set{
					// Validate this Set value must either be:
					//  - Between 1 and 2 elements
					//  - At least 4 elements
					setvalidator.Any(
						setvalidator.SizeBetween(1, 2),
						setvalidator.SizeAtLeast(4),
					),
				},
			},
		},
	}
}

AnyWithAllWarnings returns a validator which ensures that any configured attribute value passes at least one of the given validators. This validator returns all warnings, including failed validators.

Use Any() to return warnings only from the passing validator.

package main

import (
	"github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
	"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
	"github.com/hashicorp/terraform-plugin-framework/schema/validator"
)

func main() {
	// Used within a Schema method of a DataSource, Provider, or Resource
	_ = schema.Schema{
		Attributes: map[string]schema.Attribute{
			"example_attr": schema.SetAttribute{
				Required: true,
				Validators: []validator.Set{
					// Validate this Set value must either be:
					//  - Between 1 and 2 elements
					//  - At least 4 elements
					setvalidator.AnyWithAllWarnings(
						setvalidator.SizeBetween(1, 2),
						setvalidator.SizeAtLeast(4),
					),
				},
			},
		},
	}
}

AtLeastOneOf checks that of a set of path.Expression, including the attribute or block this validator is applied to, at least one has a non-null value.

This implements the validation logic declaratively within the tfsdk.Schema. Refer to [datasourcevalidator.AtLeastOneOf], [providervalidator.AtLeastOneOf], or [resourcevalidator.AtLeastOneOf] for declaring this type of validation outside the schema definition.

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

package main

import (
	"github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
	"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
	"github.com/hashicorp/terraform-plugin-framework/path"
	"github.com/hashicorp/terraform-plugin-framework/schema/validator"
	"github.com/hashicorp/terraform-plugin-framework/types"
)

func main() {
	// Used within a Schema method of a DataSource, Provider, or Resource
	_ = schema.Schema{
		Attributes: map[string]schema.Attribute{
			"example_attr": schema.SetAttribute{
				ElementType: types.StringType,
				Optional:    true,
				Validators: []validator.Set{
					// Validate at least this attribute or other_attr should be configured.
					setvalidator.AtLeastOneOf(path.Expressions{
						path.MatchRoot("other_attr"),
					}...),
				},
			},
			"other_attr": schema.StringAttribute{
				Optional: true,
			},
		},
	}
}

ConflictsWith checks that a set of path.Expression, including the attribute or block the validator is applied to, do not have a value simultaneously.

This implements the validation logic declaratively within the schema. Refer to [datasourcevalidator.Conflicting], [providervalidator.Conflicting], or [resourcevalidator.Conflicting] for declaring this type of validation outside the schema definition.

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

package main

import (
	"github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
	"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
	"github.com/hashicorp/terraform-plugin-framework/path"
	"github.com/hashicorp/terraform-plugin-framework/schema/validator"
	"github.com/hashicorp/terraform-plugin-framework/types"
)

func main() {
	// Used within a Schema method of a DataSource, Provider, or Resource
	_ = schema.Schema{
		Attributes: map[string]schema.Attribute{
			"example_attr": schema.SetAttribute{
				ElementType: types.StringType,
				Optional:    true,
				Validators: []validator.Set{
					// Validate this attribute must not be configured with other_attr.
					setvalidator.ConflictsWith(path.Expressions{
						path.MatchRoot("other_attr"),
					}...),
				},
			},
			"other_attr": schema.StringAttribute{
				Optional: true,
			},
		},
	}
}

ExactlyOneOf checks that of a set of path.Expression, including the attribute or block the validator is applied to, one and only one attribute has a value. It will also cause a validation error if none are specified.

This implements the validation logic declaratively within the schema. Refer to [datasourcevalidator.ExactlyOneOf], [providervalidator.ExactlyOneOf], or [resourcevalidator.ExactlyOneOf] for declaring this type of validation outside the schema definition.

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

package main

import (
	"github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
	"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
	"github.com/hashicorp/terraform-plugin-framework/path"
	"github.com/hashicorp/terraform-plugin-framework/schema/validator"
	"github.com/hashicorp/terraform-plugin-framework/types"
)

func main() {
	// Used within a Schema method of a DataSource, Provider, or Resource
	_ = schema.Schema{
		Attributes: map[string]schema.Attribute{
			"example_attr": schema.SetAttribute{
				ElementType: types.StringType,
				Optional:    true,
				Validators: []validator.Set{
					// Validate only this attribute or other_attr is configured.
					setvalidator.ExactlyOneOf(path.Expressions{
						path.MatchRoot("other_attr"),
					}...),
				},
			},
			"other_attr": schema.StringAttribute{
				Optional: true,
			},
		},
	}
}

IsRequired returns a validator which ensures that any configured set has a value (not null).

This validator is equivalent to the `Required` field on attributes and is only practical for use with `schema.SetNestedBlock`

package main

import (
	"github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
	"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
	"github.com/hashicorp/terraform-plugin-framework/schema/validator"
)

func main() {
	// Used within a Schema method of a DataSource, Provider, or Resource
	_ = schema.Schema{
		Blocks: map[string]schema.Block{
			"example_block": schema.SetNestedBlock{
				Validators: []validator.Set{
					// Validate this block has a value (not null).
					setvalidator.IsRequired(),
				},
				NestedObject: schema.NestedBlockObject{
					Attributes: map[string]schema.Attribute{
						"example_string_attribute": schema.StringAttribute{
							Required: true,
						},
					},
				},
			},
		},
	}
}
func NoNullValues() noNullValuesValidator

NoNullValues returns a validator which ensures that any configured set only contains non-null values.

package main

import (
	"github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
	"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
	"github.com/hashicorp/terraform-plugin-framework/schema/validator"
	"github.com/hashicorp/terraform-plugin-framework/types"
)

func main() {
	// Used within a Schema method of a DataSource, Provider, or Resource
	_ = schema.Schema{
		Attributes: map[string]schema.Attribute{
			"example_attr": schema.SetAttribute{
				ElementType: types.StringType,
				Required:    true,
				Validators: []validator.Set{
					// Validate this set must contain no null values.
					setvalidator.NoNullValues(),
				},
			},
		},
	}
}
package main

import (
	"github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
	"github.com/hashicorp/terraform-plugin-framework/function"
)

func main() {
	_ = function.Definition{
		Parameters: []function.Parameter{
			function.SetParameter{
				Name: "example_param",
				Validators: []function.SetParameterValidator{
					// Validate this set must contain no null values.
					setvalidator.NoNullValues(),
				},
			},
		},
	}
}
func SizeAtLeast(minVal int) sizeAtLeastValidator

SizeAtLeast returns an AttributeValidator which ensures that any configured attribute or function parameter value:

Null (unconfigured) and unknown (known after apply) values are skipped.

package main

import (
	"github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
	"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
	"github.com/hashicorp/terraform-plugin-framework/schema/validator"
	"github.com/hashicorp/terraform-plugin-framework/types"
)

func main() {
	// Used within a Schema method of a DataSource, Provider, or Resource
	_ = schema.Schema{
		Attributes: map[string]schema.Attribute{
			"example_attr": schema.SetAttribute{
				ElementType: types.StringType,
				Required:    true,
				Validators: []validator.Set{
					// Validate this set must contain at least 2 elements.
					setvalidator.SizeAtLeast(2),
				},
			},
		},
	}
}
package main

import (
	"github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
	"github.com/hashicorp/terraform-plugin-framework/function"
)

func main() {
	_ = function.Definition{
		Parameters: []function.Parameter{
			function.SetParameter{
				Name: "example_param",
				Validators: []function.SetParameterValidator{
					// Validate this set must contain at least 2 elements.
					setvalidator.SizeAtLeast(2),
				},
			},
		},
	}
}
func SizeAtMost(maxVal int) sizeAtMostValidator

SizeAtMost returns an AttributeValidator which ensures that any configured attribute or function parameter value:

Null (unconfigured) and unknown (known after apply) values are skipped.

package main

import (
	"github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
	"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
	"github.com/hashicorp/terraform-plugin-framework/schema/validator"
	"github.com/hashicorp/terraform-plugin-framework/types"
)

func main() {
	// Used within a Schema method of a DataSource, Provider, or Resource
	_ = schema.Schema{
		Attributes: map[string]schema.Attribute{
			"example_attr": schema.SetAttribute{
				ElementType: types.StringType,
				Required:    true,
				Validators: []validator.Set{
					// Validate this set must contain at most 2 elements.
					setvalidator.SizeAtMost(2),
				},
			},
		},
	}
}
package main

import (
	"github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
	"github.com/hashicorp/terraform-plugin-framework/function"
)

func main() {
	_ = function.Definition{
		Parameters: []function.Parameter{
			function.SetParameter{
				Name: "example_param",
				Validators: []function.SetParameterValidator{
					// Validate this set must contain at most 2 elements.
					setvalidator.SizeAtMost(2),
				},
			},
		},
	}
}
func SizeBetween(minVal, maxVal int) sizeBetweenValidator

SizeBetween returns an AttributeValidator which ensures that any configured attribute or function parameter value:

Null (unconfigured) and unknown (known after apply) values are skipped.

package main

import (
	"github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
	"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
	"github.com/hashicorp/terraform-plugin-framework/schema/validator"
	"github.com/hashicorp/terraform-plugin-framework/types"
)

func main() {
	// Used within a Schema method of a DataSource, Provider, or Resource
	_ = schema.Schema{
		Attributes: map[string]schema.Attribute{
			"example_attr": schema.SetAttribute{
				ElementType: types.StringType,
				Required:    true,
				Validators: []validator.Set{
					// Validate this set must contain at least 2 and at most 4 elements.
					setvalidator.SizeBetween(2, 4),
				},
			},
		},
	}
}
package main

import (
	"github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
	"github.com/hashicorp/terraform-plugin-framework/function"
)

func main() {
	_ = function.Definition{
		Parameters: []function.Parameter{
			function.SetParameter{
				Name: "example_param",
				Validators: []function.SetParameterValidator{
					// Validate this set must contain at least 2 and at most 4 elements.
					setvalidator.SizeBetween(2, 4),
				},
			},
		},
	}
}

ValueFloat32sAre returns an validator which ensures that any configured Float32 values passes each Float32 validator.

Null (unconfigured) and unknown (known after apply) values are skipped.

package main

import (
	"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
	"github.com/hashicorp/terraform-plugin-framework/schema/validator"
	"github.com/hashicorp/terraform-plugin-framework/types"

	"github.com/hashicorp/terraform-plugin-framework-validators/float32validator"
	"github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
)

func main() {
	// Used within a Schema method of a DataSource, Provider, or Resource
	_ = schema.Schema{
		Attributes: map[string]schema.Attribute{
			"example_attr": schema.SetAttribute{
				ElementType: types.Float32Type,
				Required:    true,
				Validators: []validator.Set{
					// Validate this Set must contain Float32 values which are at least 1.2.
					setvalidator.ValueFloat32sAre(float32validator.AtLeast(1.2)),
				},
			},
		},
	}
}

ValueFloat64sAre returns an validator which ensures that any configured Float64 values passes each Float64 validator.

Null (unconfigured) and unknown (known after apply) values are skipped.

package main

import (
	"github.com/hashicorp/terraform-plugin-framework-validators/float64validator"
	"github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
	"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
	"github.com/hashicorp/terraform-plugin-framework/schema/validator"
	"github.com/hashicorp/terraform-plugin-framework/types"
)

func main() {
	// Used within a Schema method of a DataSource, Provider, or Resource
	_ = schema.Schema{
		Attributes: map[string]schema.Attribute{
			"example_attr": schema.SetAttribute{
				ElementType: types.Float64Type,
				Required:    true,
				Validators: []validator.Set{
					// Validate this Set must contain Float64 values which are at least 1.2.
					setvalidator.ValueFloat64sAre(float64validator.AtLeast(1.2)),
				},
			},
		},
	}
}

ValueInt32sAre returns an validator which ensures that any configured Int32 values passes each Int32 validator.

Null (unconfigured) and unknown (known after apply) values are skipped.

package main

import (
	"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
	"github.com/hashicorp/terraform-plugin-framework/schema/validator"
	"github.com/hashicorp/terraform-plugin-framework/types"

	"github.com/hashicorp/terraform-plugin-framework-validators/int32validator"
	"github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
)

func main() {
	// Used within a Schema method of a DataSource, Provider, or Resource
	_ = schema.Schema{
		Attributes: map[string]schema.Attribute{
			"example_attr": schema.SetAttribute{
				ElementType: types.Int32Type,
				Required:    true,
				Validators: []validator.Set{
					// Validate this Set must contain Int32 values which are at least 1.
					setvalidator.ValueInt32sAre(int32validator.AtLeast(1)),
				},
			},
		},
	}
}

ValueInt64sAre returns an validator which ensures that any configured Int64 values passes each Int64 validator.

Null (unconfigured) and unknown (known after apply) values are skipped.

package main

import (
	"github.com/hashicorp/terraform-plugin-framework-validators/int64validator"
	"github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
	"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
	"github.com/hashicorp/terraform-plugin-framework/schema/validator"
	"github.com/hashicorp/terraform-plugin-framework/types"
)

func main() {
	// Used within a Schema method of a DataSource, Provider, or Resource
	_ = schema.Schema{
		Attributes: map[string]schema.Attribute{
			"example_attr": schema.SetAttribute{
				ElementType: types.Int64Type,
				Required:    true,
				Validators: []validator.Set{
					// Validate this Set must contain Int64 values which are at least 1.
					setvalidator.ValueInt64sAre(int64validator.AtLeast(1)),
				},
			},
		},
	}
}

ValueListsAre returns an validator which ensures that any configured List values passes each List validator.

Null (unconfigured) and unknown (known after apply) values are skipped.

package main

import (
	"github.com/hashicorp/terraform-plugin-framework-validators/listvalidator"
	"github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
	"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
	"github.com/hashicorp/terraform-plugin-framework/schema/validator"
	"github.com/hashicorp/terraform-plugin-framework/types"
)

func main() {
	// Used within a Schema method of a DataSource, Provider, or Resource
	_ = schema.Schema{
		Attributes: map[string]schema.Attribute{
			"example_attr": schema.SetAttribute{
				// This Set has values of Lists of Strings.
				// Roughly equivalent to [][]string.
				ElementType: types.ListType{
					ElemType: types.StringType,
				},
				Required: true,
				Validators: []validator.Set{
					// Validate this Set must contain List elements
					// which have at least 1 String element.
					setvalidator.ValueListsAre(listvalidator.SizeAtLeast(1)),
				},
			},
		},
	}
}

ValueMapsAre returns an validator which ensures that any configured Map values passes each Map validator.

Null (unconfigured) and unknown (known after apply) values are skipped.

package main

import (
	"github.com/hashicorp/terraform-plugin-framework-validators/mapvalidator"
	"github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
	"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
	"github.com/hashicorp/terraform-plugin-framework/schema/validator"
	"github.com/hashicorp/terraform-plugin-framework/types"
)

func main() {
	// Used within a Schema method of a DataSource, Provider, or Resource
	_ = schema.Schema{
		Attributes: map[string]schema.Attribute{
			"example_attr": schema.SetAttribute{
				// This Set has values of Maps of Strings.
				// Roughly equivalent to []map[string]string.
				ElementType: types.MapType{
					ElemType: types.StringType,
				},
				Required: true,
				Validators: []validator.Set{
					// Validate this Set must contain Map elements
					// which have at least 1 element.
					setvalidator.ValueMapsAre(mapvalidator.SizeAtLeast(1)),
				},
			},
		},
	}
}

ValueNumbersAre returns an validator which ensures that any configured Number values passes each Number validator.

Null (unconfigured) and unknown (known after apply) values are skipped.

package main

import (
	"math/big"

	"github.com/hashicorp/terraform-plugin-framework-validators/numbervalidator"
	"github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
	"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
	"github.com/hashicorp/terraform-plugin-framework/schema/validator"
	"github.com/hashicorp/terraform-plugin-framework/types"
)

func main() {
	// Used within a Schema method of a DataSource, Provider, or Resource
	_ = schema.Schema{
		Attributes: map[string]schema.Attribute{
			"example_attr": schema.SetAttribute{
				ElementType: types.NumberType,
				Required:    true,
				Validators: []validator.Set{
					// Validate this Set must contain Number values which are 1.2 or 2.4.
					setvalidator.ValueNumbersAre(
						numbervalidator.OneOf(
							big.NewFloat(1.2),
							big.NewFloat(2.4),
						),
					),
				},
			},
		},
	}
}

ValueSetsAre returns an validator which ensures that any configured Set values passes each Set validator.

Null (unconfigured) and unknown (known after apply) values are skipped.

package main

import (
	"github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
	"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
	"github.com/hashicorp/terraform-plugin-framework/schema/validator"
	"github.com/hashicorp/terraform-plugin-framework/types"
)

func main() {
	// Used within a Schema method of a DataSource, Provider, or Resource
	_ = schema.Schema{
		Attributes: map[string]schema.Attribute{
			"example_attr": schema.SetAttribute{
				// This Set has values of Sets of Strings.
				// Roughly equivalent to [][]string.
				ElementType: types.SetType{
					ElemType: types.StringType,
				},
				Required: true,
				Validators: []validator.Set{
					// Validate this Set must contain Set elements
					// which have at least 1 String element.
					setvalidator.ValueSetsAre(setvalidator.SizeAtLeast(1)),
				},
			},
		},
	}
}

ValueStringsAre returns an validator which ensures that any configured String values passes each String validator.

Null (unconfigured) and unknown (known after apply) values are skipped.

package main

import (
	"github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
	"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
	"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
	"github.com/hashicorp/terraform-plugin-framework/schema/validator"
	"github.com/hashicorp/terraform-plugin-framework/types"
)

func main() {
	// Used within a Schema method of a DataSource, Provider, or Resource
	_ = schema.Schema{
		Attributes: map[string]schema.Attribute{
			"example_attr": schema.SetAttribute{
				ElementType: types.StringType,
				Required:    true,
				Validators: []validator.Set{
					// Validate this Set must contain string values which are at least 3 characters.
					setvalidator.ValueStringsAre(stringvalidator.LengthAtLeast(3)),
				},
			},
		},
	}
}

This section is empty.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4