Skip to content
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

Merged
merged 1 commit into from Dec 16, 2022

Commits on Dec 15, 2022

  1. 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.
    AaronFriel committed Dec 15, 2022
    Configuration menu
    Copy the full SHA
    71603dc View commit details
    Browse the repository at this point in the history