pulumi / pulumi-gcp

A Google Cloud Platform (GCP) Pulumi resource package, providing multi-language access to GCP
Apache License 2.0
177 stars 51 forks source link

enabling cloud billing on a project using the gcp.billing.ProjectInfo class returns 404. #1212

Closed aaron-tillekeratne closed 10 months ago

aaron-tillekeratne commented 10 months ago

What happened?

Trying to enable billing on a newly created GCP project using gcp.billing.ProjectIinfo() returns `gcp:billing:ProjectInfo (billing-account-association): error: 1 error occurred:

Example

import pulumi_gcp as gcp

ORG_ID="some-org-id"
PROJECT_ID="foo"
BILLING_ACCOUNT_ID="some-billing-account-id"
# create a project
proj= gcp.organizations.Project(
            resource_name="project",
            project_id=PROJECT_ID,
            org_id=ORG_ID,
        )
# enable cloud billing api
billing_api = gcp.projects.Service(
            resource_name="billing-api",
            project=proj.id,
            service="cloudbilling.googleapis.com",
            opts=pulumi.ResourceOptions(depends_on=proj),
        )
# associate billing 
gcp.billing.ProjectInfo(
            resource_name="billing-account-association",
            billing_account=BILLING_ACCOUNT_ID,
            project=proj.id,
            opts=pulumi.ResourceOptions(depends_on=[billing_api]),
        )

Output of pulumi about

CLI
Version 3.84.0 Go Version go1.21.1 Go Compiler gc

Plugins NAME VERSION gcp 6.66.0 python unknown

Host
OS debian Version 11.7 Arch x86_64

This project is written in python: executable='/usr/local/bin/python3' version='3.11.5

Additional context

The pulumi AI is also not producing runnable python code in regards to this matter.

Contributing

Vote on this issue by adding a 👍 reaction. To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

mikhailshilkov commented 10 months ago

It looks like the URL is indeed incorrect: /v1/projects/projects/{project-name}/billingInfo/?alt=json has two projects in it. I suppose that it's because you should pass proj.project_id(project name) instead of proj.id (resource ID):

gcp.billing.ProjectInfo(
            resource_name="billing-account-association",
            billing_account=BILLING_ACCOUNT_ID,
            project=proj.project_id, # here
            opts=pulumi.ResourceOptions(depends_on=[billing_api]),
        )

Could you please give it a try?

aaron-tillekeratne commented 10 months ago

Hi @mikhailshilkov , yep you're correct. it should be proj.project_id. It worked fine after that. Closing this one.