pulumi / pulumi-gcp

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

Unable to deploy rewrite to CloudRun in Firebase hosting #1224

Closed 0xJem closed 11 months ago

0xJem commented 11 months ago

What happened?

I have a Cloud Run service set up in us-central (gcp:region is set to this in the stack's definition file and exposed through gcpConfig.require("region"), which I can access directly and works fine.

I have Firebase hosting setup to do a rewrite to the Cloud Run instance.

When I deploy the Firebase HostingVersion, I receive this error:

gcp:firebase:HostingVersion (XXX):
    error: 1 error occurred:
        * Error creating Version: googleapi: Error 400: Cloud Run region `us-central1` is not supported.

Example

Cloud Run definition:

const cloudRun = new gcp.cloudrunv2.Service(
  projectName,
  {
    location: gcpConfig.require("region"),

Firebase HostingVersion definition:

const firebaseHostingVersion = new gcp.firebase.HostingVersion(
  projectName,
  {
    siteId: firebaseSiteIdInput,
    config: {
      rewrites: [
        {
          glob: "**",
          run: {
            region: gcpConfig.require("region"),
            serviceId: cloudRun.id,
          },
        },
      ],

Output of pulumi about

CLI          
Version      3.68.0
Go Version   go1.20.4
Go Compiler  gc

Plugins
NAME    VERSION
nodejs  unknown

Host     
OS       ubuntu
Version  22.04
Arch     x86_64

This project is written in nodejs: executable='/home/gitpod/.nvm/versions/node/v18.18.0/bin/node' version='v18.18.0'

Current Stack: 0xJem/XXX/dev

TYPE                                        URN
pulumi:pulumi:Stack                         urn:pulumi:dev::XXX::pulumi:pulumi:Stack::XXX-dev
pulumi:providers:gcp                        urn:pulumi:dev::XXX::pulumi:providers:gcp::default_6_66_0
gcp:projects/service:Service                urn:pulumi:dev::XXX::gcp:projects/service:Service::artifact-registry
gcp:projects/service:Service                urn:pulumi:dev::XXX::gcp:projects/service:Service::cloud-run
gcp:projects/service:Service                urn:pulumi:dev::XXX::gcp:projects/service:Service::firebase
gcp:artifactregistry/repository:Repository  urn:pulumi:dev::XXX::gcp:artifactregistry/repository:Repository::XXX
gcp:firebase/project:Project                urn:pulumi:dev::XXX::gcp:firebase/project:Project::XXX
pulumi:providers:docker                     urn:pulumi:dev::XXX::pulumi:providers:docker::default_4_4_1
gcp:firebase/hostingSite:HostingSite        urn:pulumi:dev::XXX::gcp:firebase/hostingSite:HostingSite::XXX
docker:index/image:Image                    urn:pulumi:dev::XXX::docker:index/image:Image::XXX-git-commit
docker:index/image:Image                    urn:pulumi:dev::XXX::docker:index/image:Image::XXX-latest
gcp:projects/service:Service                urn:pulumi:dev::XXX::gcp:projects/service:Service::cloud-run-integrations
gcp:cloudrunv2/service:Service              urn:pulumi:dev::XXX::gcp:cloudrunv2/service:Service::XXX

Found no pending operations associated with dev

Backend        
Name           pulumi.com
URL            https://app.pulumi.com/0xJem
User           0xJem
Organizations  0xJem, OlympusDAO

Dependencies:
NAME              VERSION
@types/node       20.5.9
ts-node           10.9.1
@pulumi/docker    4.4.1
@pulumi/gcp       6.66.0
@pulumi/pulumi    3.85.0
@types/jest       29.5.5
@upstash/redis    1.22.0
@wundergraph/sdk  0.178.1
date-fns          2.30.0
jest              29.7.0
ts-jest           29.1.1
typescript        5.2.2

Pulumi locates its logs in /tmp by default

Additional context

I wasn't sure if this was an underlying GCP or API issue, so I tried to enable firebase hosting via the Cloud Run admin interface. When I added a unique site id (i.e. not one created using Pulumi), it worked.

Screenshot 2023-09-29 at 15 13 00

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).

0xJem commented 11 months ago

Ah, the difference is that the Firebase Hosting configuration via Cloud Run is a redirect, not a rewrite, and that causes problems with CORS.

mikhailshilkov commented 11 months ago

The error message strongly implies it's a Google-side issue. But also, HostingVersion is a beta resource and may still be under active development. Anyway, I don't expect the issue can be fixed on Pulumi side...

0xJem commented 11 months ago

@mikhailshilkov thanks for the clarification. I'll see if I can debug the API calls and report them to Google.

0xJem commented 11 months ago

Turns out that the rewrite should refer to the name property instead of the id. Fixed!