Open magodo opened 1 year ago
Hi @magodo! Thanks for reporting this.
The intention for provider_meta
is a very narrow use-case: whenever a module is written by the same organization as the provider it uses, it allows the author of both to use the provider to gather usage metrics about their modules by including metadata in requests made to the provider.
This was implemented to meet a very specific partner request and is not a feature we plan to expand to other use-cases. I believe the current behavior is that all configurations for the named provider should be associated with that metadata, because the content of the provider_meta
block is supposed to be describing characteristics of the module it's embedded into rather than settings for the provider. Settings that control the provider itself belong in a provider
block, not in a provider_meta
block.
However, it is definitely not intended that it should crash when you specify an invalid provider local name in the label, so there is a configuration decoding bug to be fixed here: the configuration decoder should notice that the label has invalid syntax and return an explicit error about that, rather than crashing.
@apparentlymart I understand my use case is not the expected scenario of the provider_meta
. Whilst, I think it is a potential valid case that sometimes we want a dynamic default value for a certain resource. Specifically, we have a same named properties (e.g. the create_method) at both the provider and the resource level, where the provider level one is the fallback value, which is used by the resouce when that property is not set at the resource level. Currently the implementation is tricky and brings unnecessary noise.
We've found that the provider_meta
is an ideal way to be used to define dynamic default value, as we can access that during plan (as is defined in the protocol). So what I really want to ask is can we have some mechanism similar to provider_meta
, but can work for provider aliases, so taht we can define dynamic default values for resources.
Hi @magodo,
The existing concept of provider configurations is the intended way to meet the use-case you described. You can describe the same arguments inside the provider's own configuration schema to allow configuring them on a per-provider-configuration basis:
provider "restful" {
header = {
foo = "bar"
}
resource = {
create_method = "PUT"
}
}
I see that your provider is using the new Terraform Plugin Framework. I believe the intended way to use the above in the Framework is for your provider's Configure
function to save these settings in fields of your provider type. You can then refer to those saved settings when handling the plan request.
provider_meta
is for describing properties of the module that it's written in rather than describing properties of the provider it's related to. If we made a version of that feature which was associated with provider configurations rather than with modules then it would be functionally equivalent to provider configurations, and so it would be a redundant protocol feature.
If you find it inconvenient to use the provider configuration settings from inside the plan implementation in your provider then I think that would be good feedback to share in the plugin framework repository; the team which develops the framework could change the design to make what you are trying to do more convenient without any changes to the Terraform language or to the plugin protocol.
Terraform Version
Use Cases
provider_meta
is used to set some provider scoped metadata, which can modify the provider behaviors (e.g. thePlanModifier
has access to that metadata). Since a same typed provider can have multiple instances via alias, that makes sense that theprovider_meta
can distinguish them.Attempted Solutions
I've tried to define an alias to my provider (named
foo
), and use it as below:Terraform panics:
Proposal
No response
References
https://github.com/magodo/terraform-provider-restful/pull/22