You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When building a provider-defined function with plugin framework, it is currently possible to create a function schema that is invalid, where two parameters (variadic or not) have the same name. When this occurs, you'll receive an error message from validation in Terraform like:
│ Error: Failed to load plugin schemas
│
│ Error while loading schemas for plugin components: Failed to obtain provider schema: Could not load the schema for provider registry.terraform.io/austinvalle/sandbox: provider
│ registry.terraform.io/austinvalle/sandbox function"test_func" reuses name "param"for both parameters 0 and 1..
│ Error: Failed to load plugin schemas
│
│ Error while loading schemas for plugin components: Failed to obtain provider schema: Could not load the schema for provider registry.terraform.io/austinvalle/sandbox: provider
│ registry.terraform.io/austinvalle/sandbox function"test_func" reuses name "param"for both parameter 0 and its variadic parameter..
Notably, this kind of invalid schema can be achieved inadvertently by omitting the parameter names in your function definition, which the framework currently defaults each name to param:
The framework logic for defaulting function parameter names should be updated to ensure each parameter name is unique. We could potentially employ a strategy of:
Defaulting parameter names to param{index number of parameter} => param1
Defaulting variadic parameter name to varparam
We may also want to consider adding validation logic to ensure the final function definition we send to Terraform has no conflicts if explicitly set:
Both proposal ideas sound great! For the second validation idea, schemas have a ValidateImplementation method for unit testing (or framework usage 😉 ), so having something similar for function definitions would be extending the existing pattern.
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
Module version
Use-cases
When building a provider-defined function with plugin framework, it is currently possible to create a function schema that is invalid, where two parameters (variadic or not) have the same name. When this occurs, you'll receive an error message from validation in Terraform like:
Notably, this kind of invalid schema can be achieved inadvertently by omitting the parameter names in your function definition, which the framework currently defaults each name to
param
:The full Terraform validation logic can be found here: https://github.com/hashicorp/terraform/blob/82361afd73ae5abb778d50e3b500fc08c2b04393/internal/terraform/context_plugins.go#L143-L168
Current Workaround
The workaround is to explicitly name each parameter (which we would already recommend for all functions):
Proposal
param{index number of parameter}
=>param1
varparam
References
types.Tuple
#923 (comment)The text was updated successfully, but these errors were encountered: