hashicorp / terraform-plugin-framework-validators

Common Use Case Validators for terraform-plugin-framework
Mozilla Public License 2.0
25 stars 12 forks source link

Support parameter-based validator interfaces `<Type>ParameterValidator` #235

Closed shrsr closed 3 weeks ago

shrsr commented 1 month ago

Module version

github.com/hashicorp/terraform-plugin-framework v1.10.0

The following snippet in the documentation https://github.com/hashicorp/terraform-plugin-framework/blob/v1.10.0/website/docs/plugin/framework/validation.mdx under the section Parameter Validation doesn't work as expected.

// Typically within the function.Definition for a function.
function.StringParameter{
    // ... other Parameter configuration ...

    Validators: []function.StringParameterValidator{
        stringvalidator.LengthBetween(10, 256),
    },
},

Actual Behavior

Error Message: cannot use stringvalidator.LengthBetween() (value of type validator.String) as function.StringParameterValidator value in array or slice literal: validator.String does not implement function.StringParameterValidator (missing method ValidateParameterString)

Additionally, I would like to know if there are any plans to support functions under stringvalidator in the function.StringParameter in the future?

austinvalle commented 1 month ago

Hey there @shrsr 👋🏻, thanks for reporting the issue.

I don't think we created a GH issue for it, but I think the original plan after hashicorp/terraform-plugin-framework#894 was to implement the new function parameter validators for all the appropriate terraform-plugin-framework-validators implementations.

I'm going to move this GH issue to the validators repo as our intention is to implement that new interface and support parameter-based validation for all the type packages (stringvalidator, int64validator, etc.)

shrsr commented 1 month ago

@austinvalle Thank you for the reply. Will the above mentioned snippet in the docs still be present because it doesn't currently work?

austinvalle commented 1 month ago

I think we'd opt to just fix the root issue of the validation implementation not being finished (this issue), which when released would make the documentation valid. Rather than adjusting the docs, fixing this issue, then re-adjusting the docs back. Additionally, our documentation releases are linked to Go module releases and we don't have any upcoming terraform-plugin-framework releases to link to ATM.

shrsr commented 1 month ago

Thanks!

austinvalle commented 3 weeks ago

Most of the validators have been updated to support function validators with the latest release v0.14.0.

There are some remaining ones like All/Any that can be tracked in #239