Documentation
¶
Overview ¶
Package listvalidator provides validators for types.List attributes.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SizeAtLeast ¶
func SizeAtLeast(min int) tfsdk.AttributeValidator
SizeAtLeast returns an AttributeValidator which ensures that any configured attribute 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/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" ) func main() { // Used within a GetSchema method of a DataSource, Provider, or Resource _ = tfsdk.Schema{ Attributes: map[string]tfsdk.Attribute{ "example_attr": { Required: true, Type: types.ListType{ ElemType: types.StringType, }, Validators: []tfsdk.AttributeValidator{ // Validate this list must contain at least 2 elements. listvalidator.SizeAtLeast(2), }, }, }, } }
func SizeAtMost ¶
func SizeAtMost(max int) tfsdk.AttributeValidator
SizeAtMost returns an AttributeValidator which ensures that any configured attribute 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/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" ) func main() { // Used within a GetSchema method of a DataSource, Provider, or Resource _ = tfsdk.Schema{ Attributes: map[string]tfsdk.Attribute{ "example_attr": { Required: true, Type: types.ListType{ ElemType: types.StringType, }, Validators: []tfsdk.AttributeValidator{ // Validate this list must contain at most 2 elements. listvalidator.SizeAtMost(2), }, }, }, } }
func SizeBetween ¶
func SizeBetween(min, max int) tfsdk.AttributeValidator
SizeBetween returns an AttributeValidator which ensures that any configured attribute 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/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" ) func main() { // Used within a GetSchema method of a DataSource, Provider, or Resource _ = tfsdk.Schema{ Attributes: map[string]tfsdk.Attribute{ "example_attr": { Required: true, Type: types.ListType{ ElemType: types.StringType, }, Validators: []tfsdk.AttributeValidator{ // Validate this list must contain at least 2 and at most 4 elements. listvalidator.SizeBetween(2, 4), }, }, }, } }
func ValuesAre ¶
func ValuesAre(valueValidators ...tfsdk.AttributeValidator) tfsdk.AttributeValidator
ValuesAre returns an AttributeValidator which ensures that any configured attribute value:
- Is a List.
- That contains list elements, each of which validate against each value 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/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" ) func main() { // Used within a GetSchema method of a DataSource, Provider, or Resource _ = tfsdk.Schema{ Attributes: map[string]tfsdk.Attribute{ "example_attr": { Required: true, Type: types.ListType{ ElemType: types.StringType, }, Validators: []tfsdk.AttributeValidator{ // Validate this list must contain string values which are at least 3 characters. listvalidator.ValuesAre(stringvalidator.LengthAtLeast(3)), }, }, }, } }
Types ¶
This section is empty.