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 are part of (or not part of) a defined set of values. For example:
- Whether a known value is contained in a defined set of values
- Whether a known value is not contained in a defined set of values
Proposal
Inside a float64validator package, create two new unexported types that satisfy the tfsdk.AttributeValidator interface:
var _ oneOfValidator = tfsdk.AttributeValidator
type oneOfValidator struct {
values []float64
}
func (v oneOfValidator) Description(ctx context.Context) string {/*...*/}
func (v oneOfValidator) MarkdownDescription(ctx context.Context) string {/*...*/}
func (v oneOfValidator) Validate(ctx context.Context, req tfsdk.ValidateAttributeRequest, resp *tfsdk.ValidateAttributeResponse) {/*...*/}
var _ noneOfValidator = tfsdk.AttributeValidator
type noneOfValidator struct {
values []float64
}
func (v noneOfValidator) Description(ctx context.Context) string {/*...*/}
func (v noneOfValidator) MarkdownDescription(ctx context.Context) string {/*...*/}
func (v noneOfValidator) Validate(ctx context.Context, req tfsdk.ValidateAttributeRequest, resp *tfsdk.ValidateAttributeResponse) {/*...*/}
Then, create exported functions that return these:
func OneOf(values float64...) AttributeValidator {/*...*/}
func NoneOf(values float64...) AttributeValidator {/*...*/}
This would allow provider developers to declare attributes such as:
tfsdk.Attribute{
// ... other fields ...
Type: types.Float64,
Validators: tfsdk.AttributeValidators{
float64validator.OneOf(1.2, 2.4, 4.8), // or OneOf([]float64{1.2, 2.4, 4.8}...)
},
},
Additional Information
No response
Code of Conduct
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.Float64values are part of (or not part of) a defined set of values. For example:Proposal
Inside a
float64validatorpackage, create two new unexported types that satisfy thetfsdk.AttributeValidatorinterface:Then, create exported functions that return these:
This would allow provider developers to declare attributes such as:
Additional Information
No response
Code of Conduct