-
Notifications
You must be signed in to change notification settings - Fork 13
Closed
Labels
enhancementNew feature or requestNew feature or requesttype/float64types.Float64 validatorstypes.Float64 validators
Milestone
Description
Terraform CLI and Framework Versions
Any Terraform CLI version; terraform-plugin-framework v0.8.0
Use Cases or Problem Statement
Provider developers should be able to generically validate types.Float64 values for their amount/size. For example:
- Whether a known value is equal or more than a certain amount, but not constrained
- Whether a known value is equal or less than a certain amount, but not constrained
- Whether a value is equal or more than a certain amount and equal or less than another amount
Proposal
Inside a float64validator package, create three new unexported types that satisfy the tfsdk.AttributeValidator interface:
var _ atLeastValidator = tfsdk.AttributeValidator
type atLeastValidator struct {
min float64
}
func (v atLeastValidator) Description(ctx context.Context) string {/*...*/}
func (v atLeastValidator) MarkdownDescription(ctx context.Context) string {/*...*/}
func (v atLeastValidator) Validate(ctx context.Context, req tfsdk.ValidateAttributeRequest, resp *tfsdk.ValidateAttributeResponse) {/*...*/}
var _ atMostValidator = tfsdk.AttributeValidator
type atMostValidator struct {
max float64
}
func (v atMostValidator) Description(ctx context.Context) string {/*...*/}
func (v atMostValidator) MarkdownDescription(ctx context.Context) string {/*...*/}
func (v atMostValidator) Validate(ctx context.Context, req tfsdk.ValidateAttributeRequest, resp *tfsdk.ValidateAttributeResponse) {/*...*/}
var _ betweenValidator = tfsdk.AttributeValidator
type betweenValidator struct {
max float64
min float64
}
func (v betweenValidator) Description(ctx context.Context) string {/*...*/}
func (v betweenValidator) MarkdownDescription(ctx context.Context) string {/*...*/}
func (v betweenValidator) Validate(ctx context.Context, req tfsdk.ValidateAttributeRequest, resp *tfsdk.ValidateAttributeResponse) {/*...*/}Then, create exported functions that return these:
func AtLeast(min float64) AttributeValidator {/*...*/}
func AtMost(max float64) AttributeValidator {/*...*/}
func Between(min float64, max float64) AttributeValidator {/*...*/}This would allow provider developers to declare attributes such as:
tfsdk.Attribute{
// ... other fields ...
Type: types.Float64,
Validators: tfsdk.AttributeValidators{
float64validator.AtLeast(1.2),
},
},Additional Information
No response
Code of Conduct
- I agree to follow this project's Code of Conduct
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requesttype/float64types.Float64 validatorstypes.Float64 validators