Documentation
¶
Overview ¶
Package mapvalidator provides validators for types.Map attributes.
Index ¶
- func KeysAre(keyValidators ...tfsdk.AttributeValidator) tfsdk.AttributeValidator
- func SizeAtLeast(min int) tfsdk.AttributeValidator
- func SizeAtMost(max int) tfsdk.AttributeValidator
- func SizeBetween(min, max int) tfsdk.AttributeValidator
- func ValuesAre(valueValidators ...tfsdk.AttributeValidator) tfsdk.AttributeValidator
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func KeysAre ¶
func KeysAre(keyValidators ...tfsdk.AttributeValidator) tfsdk.AttributeValidator
Example ¶
package main
import (
"github.com/hashicorp/terraform-plugin-framework-validators/mapvalidator"
"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.MapType{
ElemType: types.StringType,
},
Validators: []tfsdk.AttributeValidator{
// Validate this map must contain string keys which are at least 3 characters.
mapvalidator.KeysAre(stringvalidator.LengthAtLeast(3)),
},
},
},
}
}
func SizeAtLeast ¶
func SizeAtLeast(min int) tfsdk.AttributeValidator
SizeAtLeast returns an AttributeValidator which ensures that any configured attribute value:
- Is a Map.
- 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/mapvalidator"
"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.MapType{
ElemType: types.StringType,
},
Validators: []tfsdk.AttributeValidator{
// Validate this map must contain at least 2 elements.
mapvalidator.SizeAtLeast(2),
},
},
},
}
}
func SizeAtMost ¶
func SizeAtMost(max int) tfsdk.AttributeValidator
SizeAtMost returns an AttributeValidator which ensures that any configured attribute value:
- Is a Map.
- 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/mapvalidator"
"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.MapType{
ElemType: types.StringType,
},
Validators: []tfsdk.AttributeValidator{
// Validate this map must contain at most 2 elements.
mapvalidator.SizeAtMost(2),
},
},
},
}
}
func SizeBetween ¶
func SizeBetween(min, max int) tfsdk.AttributeValidator
SizeBetween returns an AttributeValidator which ensures that any configured attribute value:
- Is a Map.
- 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/mapvalidator"
"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.MapType{
ElemType: types.StringType,
},
Validators: []tfsdk.AttributeValidator{
// Validate this map must contain at least 2 and at most 4 elements.
mapvalidator.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 Map.
- Contains Map 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/mapvalidator"
"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.MapType{
ElemType: types.StringType,
},
Validators: []tfsdk.AttributeValidator{
// Validate this map must contain string values which are at least 3 characters.
mapvalidator.ValuesAre(stringvalidator.LengthAtLeast(3)),
},
},
},
}
}
Types ¶
This section is empty.