-
Notifications
You must be signed in to change notification settings - Fork 9.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check Provider Schema Attribute Configurability During Parsing/Validation #30669
Comments
Another validation implemented by |
Thanks for recording this, @bflad. The "requiredness" is currently handled by mapping the Terraform schema idea of required onto the One way we could try to address this is to make Terraform generate a If that won't work then we can of course add some additional logic into the main validation codepath in Terraform Core, but I mention the above just because it seems to be the place where we're currently handling concerns like this, and so it would be nice to handle everything in one place if possible. |
I can't find any released older version of Terraform which uses |
Leaving a comment here for tracking. I have just encountered this issue in my work to port the TLS Provider to FW: as part of this, there is a field that after deprecation (during which was We had tests during the deprecation phase, but of course with the |
terraform-plugin-framework v0.9.0 and later include error diagnostics "Invalid Configuration for Read-Only Attribute" and "Missing Configuration for Required Attribute" during the Another related part of this is that we also have a similar issue with Terraform 0.12 through 0.15.1 not returning diagnostics for Block MaxItems/MinItems, which we will also handle on the provider side, also during the These cases do raise an interesting question though, that might be worth pondering on. Given that HCL's validation is mostly syntax tokenization and type-based in nature, except for a limited number of cases such as block count, and the provider-based validation can handle everything surrounding the semantics of schema-based data values, is it actually worth having a delineation be drawn? I could see a few pros and cons to saying that providers are wholly responsible for validation after Terraform's configuration handling ensures that the type/value structure itself is valid. More concretely, I am referring to not necessarily sending Required/MaxItems/MinItems across the protocol. Some potential benefits:
Some potential tradeoffs:
I'm curious if you have any particular thoughts here though! If HCL/Terraform does have further plans for value-based validation, then that might render a lot of this thinking moot. |
I agree that leaving the bulk of the validation to the provider/sdk is a good idea here. For example, the Min/Max values are not really useful in core, because of Terraform's I took a look into actually using a Walking the schema and decoded config and manually checking for non-null computed values would probably be a lot less invasive (and there's probably already a similar walk done already which could also serve to validate this). |
I think our current situation essentially unfolded from us not having a clear model during early v0.12 development of which parts of the work were being handled by Terraform Core and which parts were being handled by the SDK, because at that point everything was tightly coupled together in a single codebase. I'm totally on board with the SDKs declining to return this extra metadata that Terraform Core doesn't need to do its work, of which Terraform Core does rely on some of the other information to implement the safety checks for the resource instance change lifecycle rules, and so e.g. returning misleading information about what is required vs. optional or what is computed vs. not may cause those safety checks to raise false positives.
If an SDK wants to emit additional schema detail that Terraform Core and consumers of its output don't strictly need then I think it would be better to design a protocol for the provider plugin to offer that to a plugin client directly, and then this SDK-specific protocol can be tailored to return whatever level of detail is appropriate for a particular SDK and its tightly-coupled supporting tools like documentation generators. That protocol and its associated client tool could then evolve totally independently of the protocol defined by Terraform Core. I think this should already be possible today by registering an additional gRPC service alongside the ones that implement the |
I don't think there is anything importantly actionable here (attribute validation will continue to remain on the provider side of the protocol) so closing to reduce issue noise. |
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. |
Current Terraform Version
Use-cases
Providers are generally required to notify Terraform CLI about the "configurability" of a managed resource, data source, or provider schema attribute via the
Required
,Optional
, andComputed
fields in the response to theGetProviderSchema
RPC. This information is already used in various Terraform CLI logic, for example, to determine whether providers are allowed to respond with their own value for the attribute.Interestingly enough though, provider development outside of using
terraform-plugin-sdk
needs to verify whether an attribute received a configured value on aComputed
-only attribute (from the Terraform configuration files) during validate, plan, or apply. Without this provider-side validation, an error diagnostic such as the below will be thrown:It is likely that this type of configuration validation was overlooked because the
terraform-plugin-sdk
already implemented it previously, but now that there are more options for provider development, we should investigate whether Terraform CLI should be handling validation like this.Attempted Solutions
For terraform-plugin-framework, adding additional internal logic to perform this same validation.
For terraform-plugin-go, finding a place to document this validation requirement.
For providers developed outside these, we would need to document it somewhere, such as the protocol.
Proposal
It appears configuration errors such as this could be caught and automatically handled before involving the provider during the validate, plan, and apply operation configuration parsing and/or validation logic. Terraform CLI should have enough schema information to know whether the configuration value is allowed to be non-
null
.After parsing a provider, managed resource, or data source configuration during the validate graph walk:
cty.Value
for the configurationcty.NullVal
value, if so, continue.Required
orOptional
, and if not set, return an error diagnosticPassing this validation should continue the Validate*Config RPC call to the provider.
References
For reference,
terraform-plugin-sdk
returned the following error diagnostic during theValidateResourceConfig
/ValidateDataSourceConfig
/PrepareProviderConfig
RPCs if it determined the attribute wasComputed
-only:The text was updated successfully, but these errors were encountered: