Documentation ¶
Overview ¶
Package listvalidator provides validators for types.List attributes and function parameters.
Index ¶
- func All(validators ...validator.List) validator.List
- func AlsoRequires(expressions ...path.Expression) validator.List
- func Any(validators ...validator.List) validator.List
- func AnyWithAllWarnings(validators ...validator.List) validator.List
- func AtLeastOneOf(expressions ...path.Expression) validator.List
- func ConflictsWith(expressions ...path.Expression) validator.List
- func ExactlyOneOf(expressions ...path.Expression) validator.List
- func IsRequired() validator.List
- func NoNullValues() noNullValuesValidator
- func SizeAtLeast(minVal int) sizeAtLeastValidator
- func SizeAtMost(maxVal int) sizeAtMostValidator
- func SizeBetween(minVal, maxVal int) sizeBetweenValidator
- func UniqueValues() uniqueValuesValidator
- func ValueFloat32sAre(elementValidators ...validator.Float32) validator.List
- func ValueFloat64sAre(elementValidators ...validator.Float64) validator.List
- func ValueInt32sAre(elementValidators ...validator.Int32) validator.List
- func ValueInt64sAre(elementValidators ...validator.Int64) validator.List
- func ValueListsAre(elementValidators ...validator.List) validator.List
- func ValueMapsAre(elementValidators ...validator.Map) validator.List
- func ValueNumbersAre(elementValidators ...validator.Number) validator.List
- func ValueSetsAre(elementValidators ...validator.Set) validator.List
- func ValueStringsAre(elementValidators ...validator.String) validator.List
Examples ¶
- All
- AlsoRequires
- Any
- AnyWithAllWarnings
- AtLeastOneOf
- ConflictsWith
- ExactlyOneOf
- IsRequired
- NoNullValues
- NoNullValues (Function)
- SizeAtLeast
- SizeAtLeast (Function)
- SizeAtMost
- SizeAtMost (Function)
- SizeBetween
- SizeBetween (Function)
- UniqueValues
- UniqueValues (Function)
- ValueFloat32sAre
- ValueFloat64sAre
- ValueInt32sAre
- ValueInt64sAre
- ValueListsAre
- ValueMapsAre
- ValueNumbersAre
- ValueSetsAre
- ValueStringsAre
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func All ¶ added in v0.7.0
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.
Example ¶
package main import ( "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" "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.ListAttribute{ ElementType: types.StringType, Required: true, Validators: []validator.List{ // Validate this List value must either be: // - More than 5 elements // - At least 2 elements, but not more than 3 elements listvalidator.Any( listvalidator.SizeAtLeast(5), listvalidator.All( listvalidator.SizeAtLeast(2), listvalidator.SizeAtMost(3), ), ), }, }, }, } }
Output:
func AlsoRequires ¶ added in v0.7.0
func AlsoRequires(expressions ...path.Expression) validator.List
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.
Example ¶
package main import ( "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" "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.ListAttribute{ ElementType: types.StringType, Optional: true, Validators: []validator.List{ // Validate this attribute must be configured with other_attr. listvalidator.AlsoRequires(path.Expressions{ path.MatchRoot("other_attr"), }...), }, }, "other_attr": schema.StringAttribute{ Optional: true, }, }, } }
Output:
func Any ¶ added in v0.7.0
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.
Example ¶
package main import ( "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" "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.ListAttribute{ Required: true, Validators: []validator.List{ // Validate this List value must either be: // - Between 1 and 2 elements // - At least 4 elements listvalidator.Any( listvalidator.SizeBetween(1, 2), listvalidator.SizeAtLeast(4), ), }, }, }, } }
Output:
func AnyWithAllWarnings ¶ added in v0.7.0
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.
Example ¶
package main import ( "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" "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.ListAttribute{ Required: true, Validators: []validator.List{ // Validate this List value must either be: // - Between 1 and 2 elements // - At least 4 elements listvalidator.AnyWithAllWarnings( listvalidator.SizeBetween(1, 2), listvalidator.SizeAtLeast(4), ), }, }, }, } }
Output:
func AtLeastOneOf ¶ added in v0.7.0
func AtLeastOneOf(expressions ...path.Expression) validator.List
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.
Example ¶
package main import ( "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" "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.ListAttribute{ ElementType: types.StringType, Optional: true, Validators: []validator.List{ // Validate at least this attribute or other_attr should be configured. listvalidator.AtLeastOneOf(path.Expressions{ path.MatchRoot("other_attr"), }...), }, }, "other_attr": schema.StringAttribute{ Optional: true, }, }, } }
Output:
func ConflictsWith ¶ added in v0.7.0
func ConflictsWith(expressions ...path.Expression) validator.List
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.
Example ¶
package main import ( "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" "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.ListAttribute{ ElementType: types.StringType, Optional: true, Validators: []validator.List{ // Validate this attribute must not be configured with other_attr. listvalidator.ConflictsWith(path.Expressions{ path.MatchRoot("other_attr"), }...), }, }, "other_attr": schema.StringAttribute{ Optional: true, }, }, } }
Output:
func ExactlyOneOf ¶ added in v0.7.0
func ExactlyOneOf(expressions ...path.Expression) validator.List
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.
Example ¶
package main import ( "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" "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.ListAttribute{ ElementType: types.StringType, Optional: true, Validators: []validator.List{ // Validate only this attribute or other_attr is configured. listvalidator.ExactlyOneOf(path.Expressions{ path.MatchRoot("other_attr"), }...), }, }, "other_attr": schema.StringAttribute{ Optional: true, }, }, } }
Output:
func IsRequired ¶ added in v0.10.0
IsRequired returns a validator which ensures that any configured list has a value (not null).
This validator is equivalent to the `Required` field on attributes and is only practical for use with `schema.ListNestedBlock`
Example ¶
package main import ( "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" "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.ListNestedBlock{ Validators: []validator.List{ // Validate this block has a value (not null). listvalidator.IsRequired(), }, NestedObject: schema.NestedBlockObject{ Attributes: map[string]schema.Attribute{ "example_string_attribute": schema.StringAttribute{ Required: true, }, }, }, }, }, } }
Output:
func NoNullValues ¶ added in v0.16.0
func NoNullValues() noNullValuesValidator
NoNullValues returns a validator which ensures that any configured list only contains non-null values.
Example ¶
package main import ( "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" "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.ListAttribute{ ElementType: types.StringType, Required: true, Validators: []validator.List{ // Validate this list must contain no null values. listvalidator.NoNullValues(), }, }, }, } }
Output:
Example (Function) ¶
package main import ( "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" "github.com/hashicorp/terraform-plugin-framework/function" ) func main() { _ = function.Definition{ Parameters: []function.Parameter{ function.ListParameter{ Name: "example_param", Validators: []function.ListParameterValidator{ // Validate this list must contain no null values. listvalidator.NoNullValues(), }, }, }, } }
Output:
func SizeAtLeast ¶
func SizeAtLeast(minVal int) sizeAtLeastValidator
SizeAtLeast returns an AttributeValidator which ensures that any configured attribute or function parameter value:
- Is a List.
- Contains at least min elements.
Null (unconfigured) and unknown (known after apply) values are skipped.
Example ¶
package main import ( "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" "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.ListAttribute{ ElementType: types.StringType, Required: true, Validators: []validator.List{ // Validate this list must contain at least 2 elements. listvalidator.SizeAtLeast(2), }, }, }, } }
Output:
Example (Function) ¶
package main import ( "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" "github.com/hashicorp/terraform-plugin-framework/function" ) func main() { _ = function.Definition{ Parameters: []function.Parameter{ function.ListParameter{ Name: "example_param", Validators: []function.ListParameterValidator{ // Validate this list must contain at least 2 elements. listvalidator.SizeAtLeast(2), }, }, }, } }
Output:
func SizeAtMost ¶
func SizeAtMost(maxVal int) sizeAtMostValidator
SizeAtMost returns an AttributeValidator which ensures that any configured attribute or function parameter value:
- Is a List.
- Contains at most max elements.
Null (unconfigured) and unknown (known after apply) values are skipped.
Example ¶
package main import ( "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" "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.ListAttribute{ ElementType: types.StringType, Required: true, Validators: []validator.List{ // Validate this list must contain at most 2 elements. listvalidator.SizeAtMost(2), }, }, }, } }
Output:
Example (Function) ¶
package main import ( "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" "github.com/hashicorp/terraform-plugin-framework/function" ) func main() { _ = function.Definition{ Parameters: []function.Parameter{ function.ListParameter{ Name: "example_param", Validators: []function.ListParameterValidator{ // Validate this list must contain at most 2 elements. listvalidator.SizeAtMost(2), }, }, }, } }
Output:
func SizeBetween ¶
func SizeBetween(minVal, maxVal int) sizeBetweenValidator
SizeBetween returns an AttributeValidator which ensures that any configured attribute or function parameter value:
- Is a List.
- Contains at least min elements and at most max elements.
Null (unconfigured) and unknown (known after apply) values are skipped.
Example ¶
package main import ( "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" "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.ListAttribute{ ElementType: types.StringType, Required: true, Validators: []validator.List{ // Validate this list must contain at least 2 and at most 4 elements. listvalidator.SizeBetween(2, 4), }, }, }, } }
Output:
Example (Function) ¶
package main import ( "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" "github.com/hashicorp/terraform-plugin-framework/function" ) func main() { _ = function.Definition{ Parameters: []function.Parameter{ function.ListParameter{ Name: "example_param", Validators: []function.ListParameterValidator{ // Validate this list must contain at least 2 and at most 4 elements. listvalidator.SizeBetween(2, 4), }, }, }, } }
Output:
func UniqueValues ¶ added in v0.9.0
func UniqueValues() uniqueValuesValidator
UniqueValues returns a validator which ensures that any configured list only contains unique values. This is similar to using a set attribute type which inherently validates unique values, but with list ordering semantics. Null (unconfigured) and unknown (known after apply) values are skipped.
Example ¶
package main import ( "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" "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.ListAttribute{ ElementType: types.StringType, Required: true, Validators: []validator.List{ // Validate this list must contain only unique values. listvalidator.UniqueValues(), }, }, }, } }
Output:
Example (Function) ¶
package main import ( "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" "github.com/hashicorp/terraform-plugin-framework/function" ) func main() { _ = function.Definition{ Parameters: []function.Parameter{ function.ListParameter{ Name: "example_param", Validators: []function.ListParameterValidator{ // Validate this list must contain only unique values. listvalidator.UniqueValues(), }, }, }, } }
Output:
func ValueFloat32sAre ¶ added in v0.13.0
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.
Example ¶
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/listvalidator" ) func main() { // Used within a Schema method of a DataSource, Provider, or Resource _ = schema.Schema{ Attributes: map[string]schema.Attribute{ "example_attr": schema.ListAttribute{ ElementType: types.Float32Type, Required: true, Validators: []validator.List{ // Validate this List must contain Float32 values which are at least 1.2. listvalidator.ValueFloat32sAre(float32validator.AtLeast(1.2)), }, }, }, } }
Output:
func ValueFloat64sAre ¶ added in v0.7.0
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.
Example ¶
package main import ( "github.com/hashicorp/terraform-plugin-framework-validators/float64validator" "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" "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.ListAttribute{ ElementType: types.Float64Type, Required: true, Validators: []validator.List{ // Validate this List must contain Float64 values which are at least 1.2. listvalidator.ValueFloat64sAre(float64validator.AtLeast(1.2)), }, }, }, } }
Output:
func ValueInt32sAre ¶ added in v0.13.0
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.
Example ¶
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/listvalidator" ) func main() { // Used within a Schema method of a DataSource, Provider, or Resource _ = schema.Schema{ Attributes: map[string]schema.Attribute{ "example_attr": schema.ListAttribute{ ElementType: types.Int32Type, Required: true, Validators: []validator.List{ // Validate this List must contain Int32 values which are at least 1. listvalidator.ValueInt32sAre(int32validator.AtLeast(1)), }, }, }, } }
Output:
func ValueInt64sAre ¶ added in v0.7.0
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.
Example ¶
package main import ( "github.com/hashicorp/terraform-plugin-framework-validators/int64validator" "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" "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.ListAttribute{ ElementType: types.Int64Type, Required: true, Validators: []validator.List{ // Validate this List must contain Int64 values which are at least 1. listvalidator.ValueInt64sAre(int64validator.AtLeast(1)), }, }, }, } }
Output:
func ValueListsAre ¶ added in v0.7.0
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.
Example ¶
package main import ( "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" "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.ListAttribute{ // This List has values of List of Strings. // Roughly equivalent to [][]string. ElementType: types.ListType{ ElemType: types.StringType, }, Required: true, Validators: []validator.List{ // Validate this List must contain List elements // which have at least 1 String element. listvalidator.ValueListsAre(listvalidator.SizeAtLeast(1)), }, }, }, } }
Output:
func ValueMapsAre ¶ added in v0.7.0
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.
Example ¶
package main import ( "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" "github.com/hashicorp/terraform-plugin-framework-validators/mapvalidator" "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.ListAttribute{ // This List has values of Map of Strings. // Roughly equivalent to []map[string]string. ElementType: types.MapType{ ElemType: types.StringType, }, Required: true, Validators: []validator.List{ // Validate this List must contain Map elements // which have at least 1 element. listvalidator.ValueMapsAre(mapvalidator.SizeAtLeast(1)), }, }, }, } }
Output:
func ValueNumbersAre ¶ added in v0.7.0
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.
Example ¶
package main import ( "math/big" "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" "github.com/hashicorp/terraform-plugin-framework-validators/numbervalidator" "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.ListAttribute{ ElementType: types.NumberType, Required: true, Validators: []validator.List{ // Validate this List must contain Number values which are 1.2 or 2.4. listvalidator.ValueNumbersAre( numbervalidator.OneOf( big.NewFloat(1.2), big.NewFloat(2.4), ), ), }, }, }, } }
Output:
func ValueSetsAre ¶ added in v0.7.0
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.
Example ¶
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.ListAttribute{ // This List has values of Sets of Strings. // Roughly equivalent to [][]string. ElementType: types.SetType{ ElemType: types.StringType, }, Required: true, Validators: []validator.List{ // Validate this List must contain Set elements // which have at least 1 String element. listvalidator.ValueSetsAre(setvalidator.SizeAtLeast(1)), }, }, }, } }
Output:
func ValueStringsAre ¶ added in v0.7.0
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.
Example ¶
package main import ( "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" "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.ListAttribute{ ElementType: types.StringType, Required: true, Validators: []validator.List{ // Validate this List must contain string values which are at least 3 characters. listvalidator.ValueStringsAre(stringvalidator.LengthAtLeast(3)), }, }, }, } }
Output:
Types ¶
This section is empty.
Source Files ¶
- all.go
- also_requires.go
- any.go
- any_with_all_warnings.go
- at_least_one_of.go
- conflicts_with.go
- doc.go
- exactly_one_of.go
- is_required.go
- no_null_values.go
- size_at_least.go
- size_at_most.go
- size_between.go
- unique_values.go
- value_float32s_are.go
- value_float64s_are.go
- value_int32s_are.go
- value_int64s_are.go
- value_lists_are.go
- value_maps_are.go
- value_numbers_are.go
- value_sets_are.go
- value_strings_are.go