Closed
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 that every types.Set
element value can be generically validated.
Proposal
Inside a setvalidator
package, create a new unexported type that satisfies the tfsdk.AttributeValidator
interface:
var _ valuesAreValidator = tfsdk.AttributeValidator
type valuesAreValidator struct {
valueValidators []AttributeValidators
}
func (v valuesAreValidator) Description(ctx context.Context) string {/*...*/}
func (v valuesAreValidator) MarkdownDescription(ctx context.Context) string {/*...*/}
func (v valuesAreValidator) Validate(ctx context.Context, req tfsdk.ValidateAttributeRequest, resp *tfsdk.ValidateAttributeResponse) {/*...*/}
Then, create an exported function that returns it:
func ValuesAre(valueValidators AttributeValidator...) AttributeValidator {/*...*/}
This would allow provider developers to declare attributes such as:
tfsdk.Attribute{
// ... other fields ...
Type: types.Set{
ElemType: types.String,
},
Validators: tfsdk.AttributeValidators{
setvalidator.ValuesAre(
stringvalidator.LengthBetween(1, 255),
stringvalidator.RegexMatches(regexp.MustCompile(`^[a-z]+$`), "must contain only lowercase alphabetical characters")
),
},
},
Additional Information
No response
Code of Conduct
- I agree to follow this project's Code of Conduct