diff --git a/.changelog/7875.txt b/.changelog/7875.txt new file mode 100644 index 00000000000..5ce8f7d31c4 --- /dev/null +++ b/.changelog/7875.txt @@ -0,0 +1,3 @@ +```release-note:bug +Update config.go and framework_config.go to use transport.Creds for all cases +``` diff --git a/google/framework_config.go b/google/framework_config.go index 90a07ea4553..6840bb5d048 100644 --- a/google/framework_config.go +++ b/google/framework_config.go @@ -1359,7 +1359,7 @@ func GetCredentials(ctx context.Context, data ProviderModel, initialCredentialsO return *creds } - creds, err := googleoauth.CredentialsFromJSON(ctx, []byte(contents), clientScopes...) + creds, err := transport.Creds(ctx, option.WithCredentialsJSON([]byte(contents)), option.WithScopes(clientScopes...)) if err != nil { diags.AddError("unable to parse credentials", err.Error()) return googleoauth.Credentials{} @@ -1383,14 +1383,12 @@ func GetCredentials(ctx context.Context, data ProviderModel, initialCredentialsO tflog.Info(ctx, "Authenticating using DefaultClient...") tflog.Info(ctx, fmt.Sprintf(" -- Scopes: %s", clientScopes)) - defaultTS, err := googleoauth.DefaultTokenSource(context.Background(), clientScopes...) + creds, err := transport.Creds(context.Background(), option.WithScopes(clientScopes...)) if err != nil { diags.AddError(fmt.Sprintf("Attempted to load application default credentials since neither `credentials` nor `access_token` was set in the provider block. "+ "No credentials loaded. To use your gcloud credentials, run 'gcloud auth application-default login'"), err.Error()) return googleoauth.Credentials{} } - return googleoauth.Credentials{ - TokenSource: defaultTS, - } + return *creds } diff --git a/google/transport/config.go b/google/transport/config.go index 9f98d168dd1..4e876a75120 100644 --- a/google/transport/config.go +++ b/google/transport/config.go @@ -1789,7 +1789,7 @@ func (c *Config) GetCredentials(clientScopes []string, initialCredentialsOnly bo return *creds, nil } - creds, err := googleoauth.CredentialsFromJSON(c.Context, []byte(contents), clientScopes...) + creds, err := transport.Creds(c.Context, option.WithCredentialsJSON([]byte(contents)), option.WithScopes(clientScopes...)) if err != nil { return googleoauth.Credentials{}, fmt.Errorf("unable to parse credentials from '%s': %s", contents, err) } @@ -1811,14 +1811,12 @@ func (c *Config) GetCredentials(clientScopes []string, initialCredentialsOnly bo log.Printf("[INFO] Authenticating using DefaultClient...") log.Printf("[INFO] -- Scopes: %s", clientScopes) - defaultTS, err := googleoauth.DefaultTokenSource(context.Background(), clientScopes...) + creds, err := transport.Creds(context.Background(), option.WithScopes(clientScopes...)) if err != nil { return googleoauth.Credentials{}, fmt.Errorf("Attempted to load application default credentials since neither `credentials` nor `access_token` was set in the provider block. No credentials loaded. To use your gcloud credentials, run 'gcloud auth application-default login'. Original error: %w", err) } - return googleoauth.Credentials{ - TokenSource: defaultTS, - }, err + return *creds, nil } // Remove the `/{{version}}/` from a base path if present.