Documentation ¶
Overview ¶
Package float64validator provides validators for types.Float64 attributes or function parameters.
Index ¶
- func All(validators ...validator.Float64) validator.Float64
- func AlsoRequires(expressions ...path.Expression) validator.Float64
- func Any(validators ...validator.Float64) validator.Float64
- func AnyWithAllWarnings(validators ...validator.Float64) validator.Float64
- func AtLeast(minVal float64) atLeastValidator
- func AtLeastOneOf(expressions ...path.Expression) validator.Float64
- func AtMost(maxVal float64) atMostValidator
- func Between(minVal, maxVal float64) betweenValidator
- func ConflictsWith(expressions ...path.Expression) validator.Float64
- func ExactlyOneOf(expressions ...path.Expression) validator.Float64
- func NoneOf(values ...float64) noneOfValidator
- func OneOf(values ...float64) oneOfValidator
Examples ¶
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/float64validator" "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.Float64Attribute{ Required: true, Validators: []validator.Float64{ // Validate this Float64 value must either be: // - 1.0 // - At least 2.0, but not 3.0 float64validator.Any( float64validator.OneOf(1.0), float64validator.All( float64validator.AtLeast(2.0), float64validator.NoneOf(3.0), ), ), }, }, }, } }
Output:
func AlsoRequires ¶ added in v0.7.0
func AlsoRequires(expressions ...path.Expression) validator.Float64
AlsoRequires checks that a set of path.Expression has a non-null value, if the current attribute 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 being validated.
Example ¶
package main import ( "github.com/hashicorp/terraform-plugin-framework-validators/float64validator" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/path" "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.Float64Attribute{ Optional: true, Validators: []validator.Float64{ // Validate this attribute must be configured with other_attr. float64validator.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/float64validator" "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.Float64Attribute{ Required: true, Validators: []validator.Float64{ // Validate this Float64 value must either be: // - 1.0 // - At least 2.0 float64validator.Any( float64validator.OneOf(1.0), float64validator.AtLeast(2.0), ), }, }, }, } }
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/float64validator" "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.Float64Attribute{ Required: true, Validators: []validator.Float64{ // Validate this Float64 value must either be: // - 1.0 // - At least 2.0 float64validator.AnyWithAllWarnings( float64validator.OneOf(1.0), float64validator.AtLeast(2.0), ), }, }, }, } }
Output:
func AtLeast ¶
func AtLeast(minVal float64) atLeastValidator
AtLeast returns an AttributeValidator which ensures that any configured attribute or function parameter value:
- Is a number, which can be represented by a 64-bit floating point.
- Is greater than or equal to the given minimum.
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/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.Float64Attribute{ Required: true, Validators: []validator.Float64{ // Validate floating point value must be at least 42.42 float64validator.AtLeast(42.42), }, }, }, } }
Output:
Example (Function) ¶
package main import ( "github.com/hashicorp/terraform-plugin-framework-validators/float64validator" "github.com/hashicorp/terraform-plugin-framework/function" ) func main() { _ = function.Definition{ Parameters: []function.Parameter{ function.Float64Parameter{ Name: "example_param", Validators: []function.Float64ParameterValidator{ // Validate floating point value must be at least 42.42 float64validator.AtLeast(42.42), }, }, }, } }
Output:
func AtLeastOneOf ¶ added in v0.7.0
func AtLeastOneOf(expressions ...path.Expression) validator.Float64
AtLeastOneOf checks that of a set of path.Expression, including the attribute 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 being validated.
Example ¶
package main import ( "github.com/hashicorp/terraform-plugin-framework-validators/float64validator" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/path" "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.Float64Attribute{ Optional: true, Validators: []validator.Float64{ // Validate at least this attribute or other_attr should be configured. float64validator.AtLeastOneOf(path.Expressions{ path.MatchRoot("other_attr"), }...), }, }, "other_attr": schema.StringAttribute{ Optional: true, }, }, } }
Output:
func AtMost ¶
func AtMost(maxVal float64) atMostValidator
AtMost returns an AttributeValidator which ensures that any configured attribute or function parameter value:
- Is a number, which can be represented by a 64-bit floating point.
- Is less than or equal to the given maximum.
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/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.Float64Attribute{ Required: true, Validators: []validator.Float64{ // Validate floating point value must be at most 42.42 float64validator.AtMost(42.42), }, }, }, } }
Output:
Example (Function) ¶
package main import ( "github.com/hashicorp/terraform-plugin-framework-validators/float64validator" "github.com/hashicorp/terraform-plugin-framework/function" ) func main() { _ = function.Definition{ Parameters: []function.Parameter{ function.Float64Parameter{ Name: "example_param", Validators: []function.Float64ParameterValidator{ // Validate floating point value must be at most 42.42 float64validator.AtMost(42.42), }, }, }, } }
Output:
func Between ¶
func Between(minVal, maxVal float64) betweenValidator
Between returns an AttributeValidator which ensures that any configured attribute or function parameter value:
- Is a number, which can be represented by a 64-bit floating point.
- Is greater than or equal to the given minimum and less than or equal to the given maximum.
Null (unconfigured) and unknown (known after apply) values are skipped.
minVal cannot be greater than maxVal. Invalid combinations of minVal and maxVal will result in an implementation error message during validation.
Example ¶
package main import ( "github.com/hashicorp/terraform-plugin-framework-validators/float64validator" "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.Float64Attribute{ Required: true, Validators: []validator.Float64{ // Validate floating point value must be at least 0.0 and at most 1.0 float64validator.Between(0.0, 1.0), }, }, }, } }
Output:
Example (Function) ¶
package main import ( "github.com/hashicorp/terraform-plugin-framework-validators/float64validator" "github.com/hashicorp/terraform-plugin-framework/function" ) func main() { _ = function.Definition{ Parameters: []function.Parameter{ function.Float64Parameter{ Name: "example_param", Validators: []function.Float64ParameterValidator{ // Validate floating point value must be at least 0.0 and at most 1.0 float64validator.Between(0.0, 1.0), }, }, }, } }
Output:
func ConflictsWith ¶ added in v0.7.0
func ConflictsWith(expressions ...path.Expression) validator.Float64
ConflictsWith checks that a set of path.Expression, including the attribute 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 being validated.
Example ¶
package main import ( "github.com/hashicorp/terraform-plugin-framework-validators/float64validator" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/path" "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.Float64Attribute{ Optional: true, Validators: []validator.Float64{ // Validate this attribute must not be configured with other_attr. float64validator.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.Float64
ExactlyOneOf checks that of a set of path.Expression, including the attribute 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 being validated.
Example ¶
package main import ( "github.com/hashicorp/terraform-plugin-framework-validators/float64validator" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/path" "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.Float64Attribute{ Optional: true, Validators: []validator.Float64{ // Validate only this attribute or other_attr is configured. float64validator.ExactlyOneOf(path.Expressions{ path.MatchRoot("other_attr"), }...), }, }, "other_attr": schema.StringAttribute{ Optional: true, }, }, } }
Output:
func NoneOf ¶ added in v0.3.0
func NoneOf(values ...float64) noneOfValidator
NoneOf checks that the float64 held in the attribute or function parameter is none of the given `values`.
Example ¶
package main import ( "github.com/hashicorp/terraform-plugin-framework-validators/float64validator" "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.Float64Attribute{ Required: true, Validators: []validator.Float64{ // Validate floating point value must not be 1.2, 2.4, or 4.8 float64validator.NoneOf([]float64{1.2, 2.4, 4.8}...), }, }, }, } }
Output:
Example (Function) ¶
package main import ( "github.com/hashicorp/terraform-plugin-framework-validators/float64validator" "github.com/hashicorp/terraform-plugin-framework/function" ) func main() { _ = function.Definition{ Parameters: []function.Parameter{ function.Float64Parameter{ Name: "example_param", Validators: []function.Float64ParameterValidator{ // Validate floating point value must not be 1.2, 2.4, or 4.8 float64validator.NoneOf([]float64{1.2, 2.4, 4.8}...), }, }, }, } }
Output:
func OneOf ¶ added in v0.3.0
func OneOf(values ...float64) oneOfValidator
OneOf checks that the float64 held in the attribute or function parameter is one of the given `values`.
Example ¶
package main import ( "github.com/hashicorp/terraform-plugin-framework-validators/float64validator" "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.Float64Attribute{ Required: true, Validators: []validator.Float64{ // Validate floating point value must be 1.2, 2.4, or 4.8 float64validator.OneOf([]float64{1.2, 2.4, 4.8}...), }, }, }, } }
Output:
Example (Function) ¶
package main import ( "github.com/hashicorp/terraform-plugin-framework-validators/float64validator" "github.com/hashicorp/terraform-plugin-framework/function" ) func main() { _ = function.Definition{ Parameters: []function.Parameter{ function.Float64Parameter{ Name: "example_param", Validators: []function.Float64ParameterValidator{ // Validate floating point value must be 1.2, 2.4, or 4.8 float64validator.OneOf([]float64{1.2, 2.4, 4.8}...), }, }, }, } }
Output:
Types ¶
This section is empty.