terraform-plugin-framework icon indicating copy to clipboard operation
terraform-plugin-framework copied to clipboard

function: Support Type-Based Validation with Argument Position Data

Open bflad opened this issue 2 years ago • 0 comments

Module version

v1.5.0 (not yet released)

Use-cases

Provider developers can create reusable custom types either in their provider codebases or as a shared Go module, such as terraform-plugin-framework-jsontypes. One nice benefit of a custom type is the ability to support type-based validation, meaning that any usage of that custom type in a schema automatically will perform the validation logic. This saves developers time and repetitive lines of code, such as declaring validators on each attribute definition.

When the type-based validation support was introduced, it was done in a manner that was using the lower-level type system (tftypes.Value) and very schema-specific (path.Path). This was documented as sub-optimal in https://github.com/hashicorp/terraform-plugin-framework/issues/589 when the framework v1.0.0 was being released, but was not handled prior due to time.

While the usage of tftypes.Value would be okay for the upcoming provider-defined function support, the path.Path usage is invalid since function argument information in diagnostics is very different. The custom type Validate method is called, however the path.Path passed is always errant since there is no schema-based path information for function arguments.

Proposal

Once #589 is sorted, add the updated type-based validation bits to internal/fromproto5.ArgumentsData() and internal/fromproto6.ArgumentsData() where it appropriately sets the function argument position for the validation request.

References

  • https://github.com/hashicorp/terraform-plugin-framework/issues/589

bflad avatar Dec 18 '23 15:12 bflad