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
fix(bridge): default value initialization for ExactlyOneOf fields #693
Conversation
Diff for pulumi-random with merge commit 2d11808 |
Diff for pulumi-azuread with merge commit 2d11808 |
Diff for pulumi-gcp with merge commit 2d11808 |
Diff for pulumi-azure with merge commit 2d11808 |
Diff for pulumi-aws with merge commit 2d11808 |
|
d7901ff
to
202e7bf
Compare
Diff for pulumi-azuread with merge commit 5310423 |
Diff for pulumi-random with merge commit 5310423 |
Diff for pulumi-gcp with merge commit 5310423 |
Diff for pulumi-azure with merge commit 5310423 |
Fixes pulumi/pulumi-cloudflare#306 In the Cloudflare provider, three fields are set to ExactlyOneOf: `api_token`, `api_key`, and `api_user_service_key`. The subroutine in `applyDefaults` that iterates over TF schema and applies default values would return on line 705 when `name == "api_token"` because: `sch.ExactlyOneOf()` returned `[]string{"api_token", "api_key", and "api_user_service_key"}`, and then the ExactlyOneOf check in the loop to set defaults (lines 701-708) would evaluate like so: ```go 676: tfs.Range(func(name string, sch shim.Schema) bool { // in the loop iteration where name == "api_token" // ... 701: for _, exactlyOneOfName := range sch.ExactlyOneOf() { // exactlyOneOfName would eventually equal "api_token" 702: if exactlyOneSchema, exists := tfs.GetOk(exactlyOneOfName); exists { // exactlyOneSchema == api_token's TF schema // exists == true 703: dv, _ := exactlyOneSchema.DefaultValue() // dv := value of CLOUDFLARE_API_TOKEN env var 704: if dv != nil { // dv != nil == true 705: return true } } } ``` This caused any field with `ExactlyOneOf` and a default value func to skip default initialization: it would always find itself in this loop as the "other" key, discover that other key had a default value, and then exit the loop.
202e7bf
to
71603dc
Compare
Diff for pulumi-random with merge commit d3623d1 |
Diff for pulumi-azuread with merge commit d3623d1 |
Diff for pulumi-aws with merge commit 5310423 |
Diff for pulumi-gcp with merge commit d3623d1 |
Diff for pulumi-azure with merge commit d3623d1 |
Diff for pulumi-aws with merge commit d3623d1 |
💯 thank you! |
Fixes pulumi/pulumi-cloudflare#306
In the Cloudflare provider, three fields are set to ExactlyOneOf:
api_token
,api_key
, andapi_user_service_key
. The subroutine inapplyDefaults
that iterates over TF schema and applies default values would return on line 705 whenname == "api_token"
because:sch.ExactlyOneOf()
returned[]string{"api_token", "api_key", and "api_user_service_key"}
, and then the ExactlyOneOf check in the loop to set defaults (lines 701-708) would evaluate like so:This caused any field with
ExactlyOneOf
and a default value func to skip default initialization: it would always find itself in this loop as the "other" key, discover that other key had a default value, and then exit the loop.