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 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 int64validator package, create two new unexported types that satisfy the tfsdk.AttributeValidator interface:
var _ oneOfValidator = tfsdk.AttributeValidator
type oneOfValidator struct {
values []int64
}
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 []int64
}
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 int64...) AttributeValidator {/*...*/}
func NoneOf(values int64...) AttributeValidator {/*...*/}
This would allow provider developers to declare attributes such as:
tfsdk.Attribute{
// ... other fields ...
Type: types.Int64,
Validators: tfsdk.AttributeValidators{
int64validator.OneOf(12, 24, 48), // or OneOf([]int64{12, 24, 48}...)
},
},
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.Int64values are part of (or not part of) a defined set of values. For example:Proposal
Inside a
int64validatorpackage, 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