diff --git a/config/gcp.spc b/config/gcp.spc index 5ff7cb38..327ee7f1 100644 --- a/config/gcp.spc +++ b/config/gcp.spc @@ -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, @@ -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 diff --git a/docs/index.md b/docs/index.md index 023a7850..fff533bd 100644 --- a/docs/index.md +++ b/docs/index.md @@ -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 @@ -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 ``` diff --git a/gcp/connection_config.go b/gcp/connection_config.go index 9a893385..d20ddfd7 100644 --- a/gcp/connection_config.go +++ b/gcp/connection_config.go @@ -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{} { diff --git a/gcp/utils.go b/gcp/utils.go index 32dc5747..308d71e7 100644 --- a/gcp/utils.go +++ b/gcp/utils.go @@ -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 }