Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(bridge): default value initialization for ExactlyOneOf fields
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.
- Loading branch information
1 parent
4786bb7
commit 71603dc
Showing
3 changed files
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters