In-built and custom validation functions and others in Terraform Plugin Framework

We are in the the process of migrating our SDKv2 to plugin to terraform framework. I noticed that there are a lot of validation functions from SDKv2 such as validation.StringIsJSON that we use but I haven’t been able to find the correct alternative for these in the framework.

  1. Can you please guide me on how these validations can be migrated to the framework implementation of our plugin schemas?

  2. We have a lot of ValidateFunc on attributes in our schemas. I understand that for any custom validation we need to implement a custom validator.
    Since we have custom validator function on a lot of the attributes is there a recommended better way or are we going to have to implement separate validators for each attribute?

Hi @maastha :wave:

There is a separate terraform-plugin-framework-validators Go module which contains common use-case validators for use with specific types (e.g., resource schema.BoolAttribute, data source schema.Float64Attribute etc). If the validation that you require is not available within terraform-plugin-framework-validators then you will likely need to create your own validator(s). There is some information in the Plugin Framework documentation regarding Creating Attribute Validators which should provide guidance on how to proceed when writing your own validators.