hashicorp / terraform-plugin-framework

A next-generation framework for building Terraform providers.
https://developer.hashicorp.com/terraform/plugin/framework
Mozilla Public License 2.0
298 stars 92 forks source link

Add parameter-based provider-defined function validation #971

Closed SBGoods closed 5 months ago

SBGoods commented 6 months ago

Closes: #894

Background

Provider-defined functions can accept parameters, or arguments as input. There is an opportunity to provide validation of such parameters in an analogous manner to the validation of values supplied in configuration for attributes, by implementing parameter-based and type-based validation for provider-defined function parameters.

This PR is concerned with the addition of parameter-based validation, which enables provider developers to define custom validators on framework-provided type parameters or on custom parameters.

<Type>Validator Interfaces

This PR adds various <Type>Validator interfaces for custom validators to implement for parameter-based validation

type BoolValidator interface {
    Validate(context.Context, BoolRequest, *BoolResponse)
}

type BoolRequest struct {
    ArgumentPosition int64
    Value types.Bool
}

type BoolResponse struct {
    Error *FuncError
}

ParameterWith<Type>Validators Interfaces

This PR adds various ParameterWith<Type>Validators interfaces for custom parameter types to implement to enable parameter-based validation

type ParameterWithBoolValidators interface {
    Parameter

    BoolValidators() []BoolValidator
}
github-actions[bot] commented 4 months ago

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions. If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.