Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/deploy/functions/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,8 @@
// Defaults to the compute service account when a function is first created as a GCF gen 2 function.
serviceAccount?: ServiceAccount | Expression<string> | 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.
Expand Down Expand Up @@ -483,7 +483,7 @@
// List param, we try resolving a String param instead.
try {
regions = params.resolveList(bdEndpoint.region, paramValues);
} catch (err: any) {

Check warning on line 486 in src/deploy/functions/build.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
if (err instanceof ExprParseError) {
regions = [params.resolveString(bdEndpoint.region, paramValues)];
} else {
Expand Down
27 changes: 27 additions & 0 deletions src/deploy/functions/prepare.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@
.to.be.rejectedWith(FirebaseError)
.then((error) => {
// Should always list latest runtimes
expect(error.message).to.include(latest("nodejs"));

Check warning on line 128 in src/deploy/functions/prepare.spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .message on an `any` value
expect(error.message).to.include(latest("python"));

Check warning on line 129 in src/deploy/functions/prepare.spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .message on an `any` value

// Should never list a decommissioned runtime
expect(error.message).to.not.include("nodejs6");

Check warning on line 132 in src/deploy/functions/prepare.spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .message on an `any` value
});
});

Expand Down Expand Up @@ -472,6 +472,33 @@
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/${build.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", () => {
Expand Down Expand Up @@ -806,7 +833,7 @@
await prepare.warnIfNewGenkitFunctionIsMissingSecrets(
backend.empty(),
backend.of(nonGenkitEndpoint),
{} as any,

Check warning on line 836 in src/deploy/functions/prepare.spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type

Check warning on line 836 in src/deploy/functions/prepare.spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe argument of type `any` assigned to a parameter of type `DeployOptions`
);
expect(confirm).to.not.be.called;
});
Expand All @@ -815,7 +842,7 @@
await prepare.warnIfNewGenkitFunctionIsMissingSecrets(
backend.empty(),
backend.of(genkitEndpointWithSecrets),
{} as any,

Check warning on line 845 in src/deploy/functions/prepare.spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type

Check warning on line 845 in src/deploy/functions/prepare.spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe argument of type `any` assigned to a parameter of type `DeployOptions`
);
expect(confirm).to.not.be.called;
});
Expand All @@ -824,7 +851,7 @@
await prepare.warnIfNewGenkitFunctionIsMissingSecrets(
backend.of(genkitEndpointWithoutSecrets),
backend.of(genkitEndpointWithoutSecrets),
{} as any,

Check warning on line 854 in src/deploy/functions/prepare.spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type

Check warning on line 854 in src/deploy/functions/prepare.spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe argument of type `any` assigned to a parameter of type `DeployOptions`
);
expect(confirm).to.not.be.called;
});
Expand Down
9 changes: 9 additions & 0 deletions src/deploy/functions/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/${build.REGION_TBD}/`)) {
endpoint.vpc.connector = endpoint.vpc.connector.replace(
`locations/${build.REGION_TBD}/`,
`locations/${region}/`,
);
}

backend.endpoints[region] = backend.endpoints[region] || {};
backend.endpoints[region][endpoint.id] = endpoint;
delete backend.endpoints[build.REGION_TBD][endpoint.id];
Expand Down
Loading