Documentation
¶
Overview ¶
Package numbervalidator provides validators for types.Number attributes.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NoneOf ¶
func NoneOf(unacceptableFloats ...*big.Float) tfsdk.AttributeValidator
NoneOf checks that the *big.Float held in the attribute is none of the given `unacceptableFloats`.
Example ¶
package main
import (
"math/big"
"github.com/hashicorp/terraform-plugin-framework-validators/numbervalidator"
"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.NumberType,
Validators: []tfsdk.AttributeValidator{
// Validate number value must not be 1.2, 2.4, or 4.8
numbervalidator.NoneOf(
[]*big.Float{
big.NewFloat(1.2),
big.NewFloat(2.4),
big.NewFloat(4.8),
}...,
),
},
},
},
}
}
Output:
func OneOf ¶
func OneOf(acceptableFloats ...*big.Float) tfsdk.AttributeValidator
OneOf checks that the *big.Float held in the attribute is one of the given `acceptableFloats`.
Example ¶
package main
import (
"math/big"
"github.com/hashicorp/terraform-plugin-framework-validators/numbervalidator"
"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.NumberType,
Validators: []tfsdk.AttributeValidator{
// Validate number value must be 1.2, 2.4, or 4.8
numbervalidator.OneOf(
[]*big.Float{
big.NewFloat(1.2),
big.NewFloat(2.4),
big.NewFloat(4.8),
}...,
),
},
},
},
}
}
Output:
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.