-
Notifications
You must be signed in to change notification settings - Fork 12
Closed
Labels
enhancementNew feature or requestNew feature or requesttype/int64types.Int64 validatorstypes.Int64 validatorstype/multiMultiple attribute validatorsMultiple attribute 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.Int64 values for their amount/size. For example:
- Whether a known value is equal or more than the sum of one or more attributes, but not constrained
- Whether a known value is equal or less than the sum of one or more attributes, but not constrained
- Whether a known value is exactly equal to the sum of one or more attributes, but not constrained
Proposal
Inside a int64validator package, create one new unexported types that satisfy the tfsdk.AttributeValidator interface:
var _ atLeastSumOfValidator = tfsdk.AttributeValidator
type atLeastSumOfValidator struct {
attributesToSum []*tftypes.AttributePath
}
func (v atLeastSumOfValidator) Description(ctx context.Context) string {/*...*/}
func (v atLeastSumOfValidator) MarkdownDescription(ctx context.Context) string {/*...*/}
func (v atLeastSumOfValidator) Validate(ctx context.Context, req tfsdk.ValidateAttributeRequest, resp *tfsdk.ValidateAttributeResponse) {/*...*/}Then, create exported functions that return these:
func AtLeastSumOf(attributesToSum []*tftypes.AttributePath) AttributeValidator {/*...*/}This would allow provider developers to declare attributes such as:
tfsdk.Attribute{
// ... other fields ...
Type: types.Int64,
Validators: tfsdk.AttributeValidators{
int64validator.AtLeastSumOf(
tftypes.NewAttributePath().WithAttributeName("attrib_one"),
tftypes.NewAttributePath().WithAttributeName("attrib_two")),
},
},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/int64types.Int64 validatorstypes.Int64 validatorstype/multiMultiple attribute validatorsMultiple attribute validators