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
For practitioners attempting to reference the id attribute, there is confusing behavior when the attribute is not configured. The quickest explanation about this problem is hashicorp/terraform-provider-aws#11554 (comment). The current Terraform Plugin SDK implicitly always sets the id attribute as part of calling (helper/schema.ResourceData).SetId(), which is required for all properly implemented managed resources and data sources. Given that the SDK allows this schema, it likely should be updated to either error check it or handle the situation automatically.
Attempted Solutions
Writing new schema validation outside the existing Terraform Plugin SDK validation seems like a lot of mostly duplicate effort.
Writing JSON schema output tooling for this case could be a lot of effort, not only to bootstrap the tool or correct jq logic, but also checking for this problem on code submission would require Terraform CLI to call the providers schema -json command against a locally built provider so its just a bit harder to setup in CI (at least for other providers that haven't needed this yet 😉 ).
Writing Go static analysis tooling for this case is difficult because it requires semantic knowledge to know that it is indeed only checking a root id attribute for a resource and code styling for setting up resources can vary across providers.
Proposal
Some options that come to mind:
Add (helper/schema.Resource).InternalValidate() logic (near the other schema checking) so provider developers receive an error during unit testing about this issue.
Automatically add Computed: true to root id attribute schemas that are missing it. Introduces magic (and probably not preferred magic), but prevents the issue.
Hi @glennsarti 👋 Sorry you ran into that frustrating situation.
Since this issue was created awhile ago, provider acceptance testing functionality has been forked into the separate terraform-plugin-testing Go module with its own website documentation. In there is a migration guide, that mainly is about updating import statements to point at the new Go module. Since terraform-plugin-testing v1.5.0, the id attribute is no longer required to exist, and there is also a lot of value add functionality only being added in the new Go module, such as Terraform version checks, plan checks, etc.
At some point the entire terraform-plugin-sdk Go module will be wholly deprecated to recommend terraform-plugin-framework and terraform-plugin-testing, but that product decision has not been scheduled. Maybe in the meantime, we can and should prioritize at least putting deprecation notices for acceptance testing functionality, since that is an "easier" sell for developers as it does not require the amount of rework as framework migrations.
SDK version
Use-cases
The following schema for a root
id
attribute is currently "valid" but does not work in all cases, especially in more recent versions of Terraform CLI:For practitioners attempting to reference the
id
attribute, there is confusing behavior when the attribute is not configured. The quickest explanation about this problem is hashicorp/terraform-provider-aws#11554 (comment). The current Terraform Plugin SDK implicitly always sets theid
attribute as part of calling(helper/schema.ResourceData).SetId()
, which is required for all properly implemented managed resources and data sources. Given that the SDK allows this schema, it likely should be updated to either error check it or handle the situation automatically.Attempted Solutions
Writing new schema validation outside the existing Terraform Plugin SDK validation seems like a lot of mostly duplicate effort.
Writing JSON schema output tooling for this case could be a lot of effort, not only to bootstrap the tool or correct
jq
logic, but also checking for this problem on code submission would require Terraform CLI to call theproviders schema -json
command against a locally built provider so its just a bit harder to setup in CI (at least for other providers that haven't needed this yet 😉 ).Writing Go static analysis tooling for this case is difficult because it requires semantic knowledge to know that it is indeed only checking a root
id
attribute for a resource and code styling for setting up resources can vary across providers.Proposal
Some options that come to mind:
(helper/schema.Resource).InternalValidate()
logic (near the other schema checking) so provider developers receive an error during unit testing about this issue.Computed: true
to rootid
attribute schemas that are missing it. Introduces magic (and probably not preferred magic), but prevents the issue.References
The text was updated successfully, but these errors were encountered: