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

Google Cloud - Client-based APIs and quota projects do not work well #2032

Open
jh-edstart opened this issue May 24, 2024 · 4 comments
Open
Labels
awaiting-upstream The issue cannot be resolved without action in another repository (may be owned by Pulumi). blocked The issue cannot be resolved without 3rd party action. kind/bug Some behavior is incorrect or out of spec

Comments

@jh-edstart
Copy link

jh-edstart commented May 24, 2024

As per https://cloud.google.com/docs/quotas/quota-project, some GCP APIs require a "quota" project to be specified.

It appears this should be possible using a custom GCP provider and setting the billingProject property. However, this does not seem to work.

Setting the environment variable GOOGLE_CLOUD_QUOTA_PROJECT does seem to work, but this also affects other resources, so can only be used as a temporary work-around.

Expected behavior

If I understand the API correctly, the following code should work:

import * as gcp from "@pulumi/gcp";

export const customQuotaProvider = new gcp.Provider("gcp-quota", {
    billingProject: "quota-12345",
    project: "my-proj"
});

export function setupInfra() {
    new gcp.orgpolicy.Policy("restrict-service-usage", {
        name: "projects/my-proj/policies/gcp.restrictServiceUsage",
        parent: "projects/my-proj",
        spec: {
            rules: [{
                values: {
                    allowedValues: [
                        "bigquery.googleapis.com",
                    ],
                },
            }],
        },

    }, {
        provider: customQuotaProvider
    });
}

Current behavior

You get an error message:

Diagnostics:
  pulumi:pulumi:Stack (my-stack):
    error: update failed

  gcp:orgpolicy:Policy (restrict-service-usage):
    error: 1 error occurred:
    	* Error creating Policy: failed to create a diff: failed to retrieve Policy resource: googleapi: Error 403: Your application is authenticating by using local Application Default Credentials. The orgpolicy.googleapis.com API requires a quota project, which is not set by default. To learn how to set your quota project, see https://cloud.google.com/docs/authentication/adc-troubleshooting/user-creds .
    Details:
    [
      {
        "@type": "type.googleapis.com/google.rpc.ErrorInfo",
        "domain": "googleapis.com",
        "metadata": {
          "consumer": "projects/my-project",
          "service": "orgpolicy.googleapis.com"
        },
        "reason": "SERVICE_DISABLED"
      }
    ]

Steps to reproduce

  • Runpulumi up with the code specified above
  • This works as a temporary work-around: GOOGLE_CLOUD_QUOTA_PROJECT=quota-12345 pulumi up. However, as stated above, this is not optimal since it will be used for all resources that are part of the current stack.

Context (Environment)

We're trying to use Pulumi to configure GCP service usage restrictions.

Affected feature

@jh-edstart jh-edstart added customer/feedback Feedback from customers needs-triage Needs attention from the triage team labels May 24, 2024
@cleverguy25 cleverguy25 transferred this issue from pulumi/pulumi-cloud-requests May 28, 2024
@VenelinMartinov
Copy link
Contributor

Hi @jh-edstart, thanks for reporting the issue here and sorry you ran into this!

I was able to repro the issue with the provided code, thank you for that!

Glad you found a workaround for the issue - it is quite unfortunate that the config doesn't work and we currently have no way of supplying an env var to a provider only.

Perhaps you can work around the issue with the quota project being used for other resources by splitting up the program and only specifying it for one of them? Automation API might be useful here too.

@VenelinMartinov VenelinMartinov removed the needs-triage Needs attention from the triage team label May 29, 2024
@mikhailshilkov
Copy link
Member

mikhailshilkov commented May 30, 2024

@VenelinMartinov Do you know if this problem is specific to the particular env var, to the particular provider, or is even broader than that? I'd love to understand the next level of details.

@mikhailshilkov mikhailshilkov added the kind/bug Some behavior is incorrect or out of spec label May 30, 2024
@VenelinMartinov VenelinMartinov self-assigned this May 30, 2024
@mikhailshilkov mikhailshilkov removed the customer/feedback Feedback from customers label May 30, 2024
@VenelinMartinov
Copy link
Contributor

VenelinMartinov commented May 30, 2024

I've reproduce the same issue in terraform:

provider "google" {
  project     = "pulumi-development"
  billing_project = "pulumi-development"
}

resource "google_org_policy_policy" "restrict_service_usage" {
  name   = "projects/pulumi-development/policies/gcp.restrictServiceUsage"
  parent = "projects/pulumi-development"

  spec {
    rules {
      values {
        allowed_values = ["bigquery.googleapis.com"]
      }
    }
  }

  provider = google
}

Raised hashicorp/terraform-provider-google#18281 upstream

@VenelinMartinov VenelinMartinov added the awaiting-upstream The issue cannot be resolved without action in another repository (may be owned by Pulumi). label May 30, 2024
@VenelinMartinov VenelinMartinov removed their assignment Jun 3, 2024
@VenelinMartinov
Copy link
Contributor

VenelinMartinov commented Aug 9, 2024

From the upstream issue: hashicorp/terraform-provider-google#18281 (comment)

It seems that the provider needs the userProjectOverride parameter set in order for billingProject to take effect.

There's also a note in the upstream docs about it, which we fail to translate: https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/provider_reference#billing_project

@iwahbe iwahbe added the blocked The issue cannot be resolved without 3rd party action. label Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-upstream The issue cannot be resolved without action in another repository (may be owned by Pulumi). blocked The issue cannot be resolved without 3rd party action. kind/bug Some behavior is incorrect or out of spec
Projects
None yet
Development

No branches or pull requests

4 participants