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

Add support for quota_project in config #556

Merged
merged 4 commits into from
Mar 29, 2024
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
9 changes: 8 additions & 1 deletion config/gcp.spc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
connection "gcp" {
plugin = "gcp"
plugin = "gcp"

# `project` (optional) - The project ID to connect to. This is the project ID (string), not the
# project name or number. If the `project` argument is not specified for a connection,
Expand All @@ -20,6 +20,13 @@ connection "gcp" {
# If not set, no impersonation is done.
#impersonate_service_account = "YOUR_SERVICE_ACCOUNT"

# `quota_project` (optional) - The project ID used for billing and quota. When set,
# this project ID is used to track quota usage and billing for the operations performed with the GCP connection.
# If `quota_project` is not specified directly, the system will look for the `GOOGLE_CLOUD_QUOTA_PROJECT`
# environment variable to determine which project to use for billing and quota.
# If neither is specified, billing and quota are tracked against the project associated with the credentials used for authentication.
# quota_project = "YOUR_QUOTA_PROJECT_ID"

# `ignore_error_codes` (optional) - List of additional GCP error codes to ignore for all queries.
# By default, common not found error codes are ignored and will still be ignored even if this argument is not set.
# Refer https://cloud.google.com/resource-manager/docs/core_errors#Global_Errors for more information on GCP error codes
Expand Down
8 changes: 8 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ connection "gcp" {
# If not set, no impersonation is done.
#impersonate_service_account = "YOUR_SERVICE_ACCOUNT"

# `quota_project` (optional) - The project ID used for billing and quota. When set,
# this project ID is used to track quota usage and billing for the operations performed with the GCP connection.
# If `quota_project` is not specified directly, the system will look for the `GOOGLE_CLOUD_QUOTA_PROJECT`
# environment variable to determine which project to use for billing and quota.
# If neither is specified, billing and quota are tracked against the project associated with the credentials used for authentication.
# quota_project = "YOUR_QUOTA_PROJECT_ID"

# `ignore_error_codes` (optional) - List of additional GCP error codes to ignore for all queries.
# By default, the common not found error codes are ignored and will still be ignored even if this argument is not set.
# Refer https://cloud.google.com/resource-manager/docs/core_errors#Global_Errors for more information on GCP error codes
Expand Down Expand Up @@ -212,5 +219,6 @@ connection "gcp_all" {

```sh
export CLOUDSDK_CORE_PROJECT=myproject
export GOOGLE_CLOUD_QUOTA_PROJECT=billingproject
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/my/creds.json
```
1 change: 1 addition & 0 deletions gcp/connection_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type gcpConfig struct {
CredentialFile *string `hcl:"credential_file"`
ImpersonateServiceAccount *string `hcl:"impersonate_service_account"`
IgnoreErrorCodes []string `hcl:"ignore_error_codes,optional"`
QuotaProject *string `hcl:"quota_project,optional"`
}

func ConfigInstance() interface{} {
Expand Down
13 changes: 13 additions & 0 deletions gcp/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,19 @@ func setSessionConfig(ctx context.Context, connection *plugin.Connection) []opti

opts = append(opts, option.WithTokenSource(ts))
}

// check if quota project is set via env var
quotaProject := os.Getenv("GOOGLE_CLOUD_QUOTA_PROJECT")

// check if quota project is set in config
if gcpConfig.QuotaProject != nil {
quotaProject = *gcpConfig.QuotaProject
}

if quotaProject != "" {
opts = append(opts, option.WithQuotaProject(quotaProject))
}

return opts
}

Expand Down
Loading