diff --git a/CHANGELOG.md b/CHANGELOG.md index aac70563f19..1ea59aee1dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,2 +1,3 @@ +- Fixed an issue where the functions service account option was not treated as a param (#6389). - Fixed an issue with deploying function groups containing v2 functions. (#6408) - Use GetDefaultBucket endpoint to fetch Storage Default Bucket. diff --git a/src/deploy/functions/build.ts b/src/deploy/functions/build.ts index 846a49043b3..573a199ab4e 100644 --- a/src/deploy/functions/build.ts +++ b/src/deploy/functions/build.ts @@ -235,7 +235,7 @@ export type Endpoint = Triggered & { // The services account that this function should run as. // defaults to the GAE service account when a function is first created as a GCF gen 1 function. // Defaults to the compute service account when a function is first created as a GCF gen 2 function. - serviceAccount?: ServiceAccount | null; + serviceAccount?: Field | ServiceAccount | null; // defaults to ["us-central1"], overridable in firebase-tools with // process.env.FIREBASE_FUNCTIONS_DEFAULT_REGION @@ -457,8 +457,7 @@ export function toBackend( bdEndpoint, "environmentVariables", "labels", - "secretEnvironmentVariables", - "serviceAccount" + "secretEnvironmentVariables" ); proto.convertIfPresent(bkEndpoint, bdEndpoint, "ingressSettings", (from) => { @@ -479,6 +478,7 @@ export function toBackend( return (mem as backend.MemoryOptions) || null; }); + r.resolveStrings(bkEndpoint, bdEndpoint, "serviceAccount"); r.resolveInts( bkEndpoint, bdEndpoint, diff --git a/src/test/deploy/functions/build.spec.ts b/src/test/deploy/functions/build.spec.ts index 873c9a2a3b7..0f29dd55f08 100644 --- a/src/test/deploy/functions/build.spec.ts +++ b/src/test/deploy/functions/build.spec.ts @@ -1,5 +1,6 @@ import { expect } from "chai"; import * as build from "../../../deploy/functions/build"; +import { ParamValue } from "../../../deploy/functions/params"; describe("toBackend", () => { it("populates backend info from Build", () => { @@ -110,4 +111,49 @@ describe("toBackend", () => { ).to.have.members(["service-account-1@", "service-account-2@"]); } }); + + it("populates multiple param values", () => { + const desiredBuild: build.Build = build.of({ + func: { + platform: "gcfv2", + region: ["us-central1"], + project: "project", + runtime: "nodejs16", + entryPoint: "func", + maxInstances: "{{ params.maxinstances }}", + minInstances: "{{ params.mininstances }}", + serviceAccount: "{{ params.serviceaccount }}", + vpc: { + connector: "projects/project/locations/region/connectors/connector", + egressSettings: "PRIVATE_RANGES_ONLY", + }, + ingressSettings: "ALLOW_ALL", + labels: { + test: "testing", + }, + httpsTrigger: { + invoker: ["service-account-2@", "service-account-3@"], + }, + }, + }); + const backend = build.toBackend(desiredBuild, { + maxinstances: new ParamValue("42", false, { number: true }), + mininstances: new ParamValue("1", false, { number: true }), + serviceaccount: new ParamValue("service-account-1@", false, { string: true }), + }); + expect(Object.keys(backend.endpoints).length).to.equal(1); + const endpointDef = Object.values(backend.endpoints)[0]; + expect(endpointDef).to.not.equal(undefined); + if (endpointDef) { + expect(endpointDef.func.id).to.equal("func"); + expect(endpointDef.func.project).to.equal("project"); + expect(endpointDef.func.region).to.equal("us-central1"); + expect(endpointDef.func.maxInstances).to.equal(42); + expect(endpointDef.func.minInstances).to.equal(1); + expect(endpointDef.func.serviceAccount).to.equal("service-account-1@"); + expect( + "httpsTrigger" in endpointDef.func ? endpointDef.func.httpsTrigger.invoker : [] + ).to.have.members(["service-account-2@", "service-account-3@"]); + } + }); });