From 2463be3870f06fa7df3acc165e0026d6dce52187 Mon Sep 17 00:00:00 2001 From: Wanda Mora Date: Thu, 7 May 2026 17:43:44 +0000 Subject: [PATCH 1/6] Resolve VPC Connector region if REGION_TBD This dynamically resolves the VPC connector region to be the same as the function if not defined. This also includes a small comment fix for the region field in Endpoint. --- src/deploy/functions/build.ts | 4 ++-- src/deploy/functions/prepare.spec.ts | 27 +++++++++++++++++++++++++++ src/deploy/functions/prepare.ts | 9 +++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/deploy/functions/build.ts b/src/deploy/functions/build.ts index df2d3950d6b..efbde154987 100644 --- a/src/deploy/functions/build.ts +++ b/src/deploy/functions/build.ts @@ -257,8 +257,8 @@ export type Endpoint = Triggered & { // Defaults to the compute service account when a function is first created as a GCF gen 2 function. serviceAccount?: ServiceAccount | Expression | null; - // defaults to ["us-central1"], overridable in firebase-tools with - // process.env.FIREBASE_FUNCTIONS_DEFAULT_REGION + // Defaults to REGION_TBD. The deployment region is resolved dynamically at deploy-time + // based on event trigger sources or matching existing functions, falling back to "us-central1". region?: ListField; // The Cloud project associated with this endpoint. diff --git a/src/deploy/functions/prepare.spec.ts b/src/deploy/functions/prepare.spec.ts index d99f1648f36..0d64744ed5c 100644 --- a/src/deploy/functions/prepare.spec.ts +++ b/src/deploy/functions/prepare.spec.ts @@ -472,6 +472,33 @@ describe("prepare", () => { expect(want.endpoints["us-central1"]?.["id"].region).to.equal("us-central1"); expect(want.endpoints[build.REGION_TBD]).to.not.exist; }); + + it("updates VPC connector region if it contains REGION_TBD placeholder when default region is resolved", async () => { + const wantE: backend.Endpoint = { + ...ENDPOINT_BASE, + id: "onArchive", + region: build.REGION_TBD, + eventTrigger: { + eventType: "google.cloud.storage.object.v1.archived", + eventFilters: { bucket: "my-bucket" }, + retry: false, + }, + vpc: { + connector: "projects/project/locations/REGION_TBD/connectors/my-connector", + }, + }; + const want = backend.of(wantE); + const have = backend.empty(); + + getBucketStub.resolves({ location: "us-east1" }); + + await prepare.resolveDefaultRegions(want, have); + + expect(want.endpoints["us-east1"]?.["onArchive"]).to.exist; + expect(want.endpoints["us-east1"]?.["onArchive"].vpc?.connector).to.equal( + "projects/project/locations/us-east1/connectors/my-connector" + ); + }); }); describe("inferDetailsFromExisting", () => { diff --git a/src/deploy/functions/prepare.ts b/src/deploy/functions/prepare.ts index ad21e308c77..a8f91ccc7d1 100644 --- a/src/deploy/functions/prepare.ts +++ b/src/deploy/functions/prepare.ts @@ -355,6 +355,15 @@ function moveEndpointToRegion( region: string, ) { endpoint.region = region; + + // Update VPC connector region if it was constructed using REGION_TBD + if (endpoint.vpc?.connector?.includes("locations/REGION_TBD/")) { + endpoint.vpc.connector = endpoint.vpc.connector.replace( + "locations/REGION_TBD/", + `locations/${region}/`, + ); + } + backend.endpoints[region] = backend.endpoints[region] || {}; backend.endpoints[region][endpoint.id] = endpoint; delete backend.endpoints[build.REGION_TBD][endpoint.id]; From a07a628febd360443fa0e2abf2215591bd430454 Mon Sep 17 00:00:00 2001 From: Wanda Mora <42626188+wandamora@users.noreply.github.com> Date: Thu, 7 May 2026 11:10:54 -0700 Subject: [PATCH 2/6] Apply suggestion from @gemini-code-assist[bot] Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- src/deploy/functions/prepare.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/deploy/functions/prepare.spec.ts b/src/deploy/functions/prepare.spec.ts index 0d64744ed5c..4646f7ea28d 100644 --- a/src/deploy/functions/prepare.spec.ts +++ b/src/deploy/functions/prepare.spec.ts @@ -484,7 +484,7 @@ describe("prepare", () => { retry: false, }, vpc: { - connector: "projects/project/locations/REGION_TBD/connectors/my-connector", + connector: `projects/project/locations/${build.REGION_TBD}/connectors/my-connector`, }, }; const want = backend.of(wantE); From 12cfad4d6e1d0ded1130efce530c022981614c23 Mon Sep 17 00:00:00 2001 From: Wanda Mora Date: Thu, 7 May 2026 17:43:44 +0000 Subject: [PATCH 3/6] Resolve VPC Connector region if REGION_TBD This dynamically resolves the VPC connector region to be the same as the function if not defined. This also includes a small comment fix for the region field in Endpoint. --- src/deploy/functions/prepare.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/deploy/functions/prepare.spec.ts b/src/deploy/functions/prepare.spec.ts index 4646f7ea28d..7b190fa2d03 100644 --- a/src/deploy/functions/prepare.spec.ts +++ b/src/deploy/functions/prepare.spec.ts @@ -496,7 +496,7 @@ describe("prepare", () => { expect(want.endpoints["us-east1"]?.["onArchive"]).to.exist; expect(want.endpoints["us-east1"]?.["onArchive"].vpc?.connector).to.equal( - "projects/project/locations/us-east1/connectors/my-connector" + "projects/project/locations/us-east1/connectors/my-connector", ); }); }); From 2c72e24aba87fcae9db8384368f3c034b72fac0f Mon Sep 17 00:00:00 2001 From: Wanda Mora <42626188+wandamora@users.noreply.github.com> Date: Thu, 7 May 2026 11:13:15 -0700 Subject: [PATCH 4/6] Apply suggestion from @gemini-code-assist[bot] Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- src/deploy/functions/prepare.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/deploy/functions/prepare.ts b/src/deploy/functions/prepare.ts index a8f91ccc7d1..addf87bd8bb 100644 --- a/src/deploy/functions/prepare.ts +++ b/src/deploy/functions/prepare.ts @@ -357,12 +357,13 @@ function moveEndpointToRegion( endpoint.region = region; // Update VPC connector region if it was constructed using REGION_TBD - if (endpoint.vpc?.connector?.includes("locations/REGION_TBD/")) { + if (endpoint.vpc?.connector?.includes(`locations/${build.REGION_TBD}/`)) { endpoint.vpc.connector = endpoint.vpc.connector.replace( - "locations/REGION_TBD/", + `locations/${build.REGION_TBD}/`, `locations/${region}/`, ); } + } backend.endpoints[region] = backend.endpoints[region] || {}; backend.endpoints[region][endpoint.id] = endpoint; From d74893c381a326dd5d24d681798c91bfe7d1d93f Mon Sep 17 00:00:00 2001 From: Wanda Mora Date: Thu, 7 May 2026 18:56:58 +0000 Subject: [PATCH 5/6] Fix bad apply suggestion --- src/deploy/functions/prepare.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/deploy/functions/prepare.ts b/src/deploy/functions/prepare.ts index addf87bd8bb..d56c87694b5 100644 --- a/src/deploy/functions/prepare.ts +++ b/src/deploy/functions/prepare.ts @@ -363,7 +363,6 @@ function moveEndpointToRegion( `locations/${region}/`, ); } - } backend.endpoints[region] = backend.endpoints[region] || {}; backend.endpoints[region][endpoint.id] = endpoint; From 7bdca5b193703be775d9f9bf8bacafc68a6a8322 Mon Sep 17 00:00:00 2001 From: Wanda Mora Date: Thu, 7 May 2026 21:40:44 +0000 Subject: [PATCH 6/6] Add CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e69de29bb2d..1ea94ce4741 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -0,0 +1 @@ +- Set region for VPC connector to match function region if not specified. (#10469) \ No newline at end of file