-
Notifications
You must be signed in to change notification settings - Fork 43
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
Prevent mutating existing 'id' property on schema #521
Conversation
@stack72 @pgavlin was there a change to the upstream providers where "id" was once an implicit property that we had add on to the schema, but due to changes upstream it now explicit and we can expect it to be present? Another example of that is cases where the I tested removing both code blocks I highlighted in my PR and running tfgen against the hcloud provider, and it removed all of the spurious and inaccurate "id" properties from the schema & SDKs like this one: https://www.pulumi.com/registry/packages/hcloud/api-docs/getnetworks/#id_yaml All of the plural getter functions in hcloud like |
Acceptance tests on hcloud using this change have passed: https://github.com/pulumi/pulumi-hcloud/actions/runs/2361216953 I agree with Friel though - would very much like to see if we can stop generating fake ID fields in the first place and clean up some of these logic twists. |
TF has been pretty inconsistent in its treatment of |
@guineveresaenger I think based on Pat's answer, we merge this PR as is, then follow up with a 2nd PR to remove both blocks that create "id" properties on data sources. That seems riskier and more likely to affect our tier 1 providers, so I want to do it separately. |
In the new plug-in SDK it only injects an Id if d.SetId is used so we need to be careful here |
I think that an HCL expression of the form |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@guineveresaenger has checked this on pulumi-aws and make tfgen showed no schema changes
Fixes pulumi/pulumi#9611 which was a bug caused by this roundabout sequence.
Bug
Examples code generation should be deterministic. Instead, for the Hetzner Cloud (hcloud) provider, the
id
properties on several functions flapped between a string or numeric representation in the docs.Root cause analysis
The Hetzner Cloud
hcloud_network
&hcloud_networks
upstream examples contain a bug, the latter docs refer tohcloud_network
(singular) in the examples and not plural.This is relevant because our own code has a data race. We intermingle schema binding (and mutating the schema) with example code generation. Depending on whether
getExample
orgetExamples
runs first, we either:getExample
(correctly)getExamples
(broken due to upstream)getExample
to have anid: string
output.Or:
getExamples
(broken due to upstream)getExample
to have anid: string
output.getExample
(incorrectly, due to mutation of id property)The change in this PR ensures that if an "id" is present, it is not overridden. Here's the mutation:
pulumi-terraform-bridge/pkg/tf2pulumi/convert/tf12.go
Line 1757 in 6d583a6
While root causing this, I found this earlier code which seems to make that line redundant, because we also "make up" a string output if one doesn't prior to doing any code generation, up front:
pulumi-terraform-bridge/pkg/tfgen/generate.go
Lines 1235 to 1243 in 6d583a6
As I'm new to this code base, I don't know why either of these blocks is needed, as I think they create phantom "id" properties on functions that do not have an "id" output, such as in the
getNetworks
example.If either or both of the quoted code blocks can be safely removed, I think we should favor doing so over this PR.