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

Update provider reference docs on quota usage and always use billing_project as quota project if appropriately specified #9012

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/12411.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
provider: fixed issue where `GOOGLE_CLOUD_QUOTA_PROJECT` env var would override explicit billing_project
```
17 changes: 15 additions & 2 deletions google-beta/transport/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1547,11 +1547,20 @@ func (c *Config) LoadAndValidate(ctx context.Context) error {
}

c.TokenSource = tokenSource

cleanCtx := context.WithValue(ctx, oauth2.HTTPClient, cleanhttp.DefaultClient())
clientOptions := []option.ClientOption{option.WithTokenSource(tokenSource)}

// The client libraries allow setting the GOOGLE_CLOUD_QUOTA_PROJECT environment variable
// directly, which unintentionally takes precedence over provider settings. Ensure that
// provider settings take precedence by applying to the client library's client directly
// b/360405077#comment8 - go/tpg-issue/17882
if c.UserProjectOverride && c.BillingProject != "" {
quotaProject := c.BillingProject
clientOptions = append(clientOptions, option.WithQuotaProject(quotaProject))
}

// 1. MTLS TRANSPORT/CLIENT - sets up proper auth headers
client, _, err := transport.NewHTTPClient(cleanCtx, option.WithTokenSource(tokenSource))
client, _, err := transport.NewHTTPClient(cleanCtx, clientOptions...)
if err != nil {
return err
}
Expand Down Expand Up @@ -1580,6 +1589,10 @@ func (c *Config) LoadAndValidate(ctx context.Context) error {

// Ensure $userProject is set for all HTTP requests using the client if specified by the provider config
// See https://cloud.google.com/apis/docs/system-parameters
// option.WithQuotaProject automatically sets the quota project in the client.
// However, this setting won't appear in our request logs since our logging
// transport sits above the Google client's internal transport. To ensure
// visibility in debug logging, we explicitly set the quota project here as well.
if c.UserProjectOverride && c.BillingProject != "" {
headerTransport.Set("X-Goog-User-Project", c.BillingProject)
}
Expand Down
6 changes: 5 additions & 1 deletion website/docs/guides/provider_reference.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,15 @@ If you are using Terraform on your workstation we recommend that you install
as a primary authentication method. You can enable ADCs by running the command
`gcloud auth application-default login`.

<!--
TODO: quota project is not currently read from ADC file b/360405077#comment8

Google Cloud reads the quota project for requests will be read automatically
from the `core/project` value. You can override this project by specifying the
`--project` flag when running `gcloud auth application-default login`. `gcloud`
should return this message if you have set the correct billing project:
`Quota project "your-project" was added to ADC which can be used by Google client libraries for billing and quota.`
`Quota project "your-project" was added to ADC which can be used by Google client libraries for billing and quota.`
-->

### Running Terraform on Google Cloud

Expand Down
Loading