Documentation
¶
Overview ¶
Package setvalidator provides validators for types.Set 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 Set.
- 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/setvalidator"
"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.SetType{
ElemType: types.StringType,
},
Validators: []tfsdk.AttributeValidator{
// Validate this set must contain at least 2 elements.
setvalidator.SizeAtLeast(2),
},
},
},
}
}
func SizeAtMost ¶
func SizeAtMost(max int) tfsdk.AttributeValidator
SizeAtMost returns an AttributeValidator which ensures that any configured attribute value:
- Is a Set.
- 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/setvalidator"
"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.SetType{
ElemType: types.StringType,
},
Validators: []tfsdk.AttributeValidator{
// Validate this set must contain at most 2 elements.
setvalidator.SizeAtMost(2),
},
},
},
}
}
func SizeBetween ¶
func SizeBetween(min, max int) tfsdk.AttributeValidator
SizeBetween returns an AttributeValidator which ensures that any configured attribute value:
- Is a Set.
- 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/setvalidator"
"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.SetType{
ElemType: types.StringType,
},
Validators: []tfsdk.AttributeValidator{
// Validate this set must contain at least 2 and at most 4 elements.
setvalidator.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 Set.
- Contains Set 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/setvalidator"
"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.SetType{
ElemType: types.StringType,
},
Validators: []tfsdk.AttributeValidator{
// Validate this set must contain string values which are at least 3 characters.
setvalidator.ValuesAre(stringvalidator.LengthAtLeast(3)),
},
},
},
}
}
Types ¶
This section is empty.