Skip to content

Commit 2657297

Browse files
colerogersjoehan
andauthored
Fix service account option to be a param (#6389)
* treat the service account option as a param * add changelog entry --------- Co-authored-by: joehan <[email protected]>
1 parent f5aa458 commit 2657297

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
- Fixed an issue where the functions service account option was not treated as a param (#6389).
12
- Fixed an issue with deploying function groups containing v2 functions. (#6408)
23
- Use GetDefaultBucket endpoint to fetch Storage Default Bucket.

src/deploy/functions/build.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ export type Endpoint = Triggered & {
235235
// The services account that this function should run as.
236236
// defaults to the GAE service account when a function is first created as a GCF gen 1 function.
237237
// Defaults to the compute service account when a function is first created as a GCF gen 2 function.
238-
serviceAccount?: ServiceAccount | null;
238+
serviceAccount?: Field<string> | ServiceAccount | null;
239239

240240
// defaults to ["us-central1"], overridable in firebase-tools with
241241
// process.env.FIREBASE_FUNCTIONS_DEFAULT_REGION
@@ -457,8 +457,7 @@ export function toBackend(
457457
bdEndpoint,
458458
"environmentVariables",
459459
"labels",
460-
"secretEnvironmentVariables",
461-
"serviceAccount"
460+
"secretEnvironmentVariables"
462461
);
463462

464463
proto.convertIfPresent(bkEndpoint, bdEndpoint, "ingressSettings", (from) => {
@@ -479,6 +478,7 @@ export function toBackend(
479478
return (mem as backend.MemoryOptions) || null;
480479
});
481480

481+
r.resolveStrings(bkEndpoint, bdEndpoint, "serviceAccount");
482482
r.resolveInts(
483483
bkEndpoint,
484484
bdEndpoint,

src/test/deploy/functions/build.spec.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { expect } from "chai";
22
import * as build from "../../../deploy/functions/build";
3+
import { ParamValue } from "../../../deploy/functions/params";
34

45
describe("toBackend", () => {
56
it("populates backend info from Build", () => {
@@ -110,4 +111,49 @@ describe("toBackend", () => {
110111
).to.have.members(["service-account-1@", "service-account-2@"]);
111112
}
112113
});
114+
115+
it("populates multiple param values", () => {
116+
const desiredBuild: build.Build = build.of({
117+
func: {
118+
platform: "gcfv2",
119+
region: ["us-central1"],
120+
project: "project",
121+
runtime: "nodejs16",
122+
entryPoint: "func",
123+
maxInstances: "{{ params.maxinstances }}",
124+
minInstances: "{{ params.mininstances }}",
125+
serviceAccount: "{{ params.serviceaccount }}",
126+
vpc: {
127+
connector: "projects/project/locations/region/connectors/connector",
128+
egressSettings: "PRIVATE_RANGES_ONLY",
129+
},
130+
ingressSettings: "ALLOW_ALL",
131+
labels: {
132+
test: "testing",
133+
},
134+
httpsTrigger: {
135+
invoker: ["service-account-2@", "service-account-3@"],
136+
},
137+
},
138+
});
139+
const backend = build.toBackend(desiredBuild, {
140+
maxinstances: new ParamValue("42", false, { number: true }),
141+
mininstances: new ParamValue("1", false, { number: true }),
142+
serviceaccount: new ParamValue("service-account-1@", false, { string: true }),
143+
});
144+
expect(Object.keys(backend.endpoints).length).to.equal(1);
145+
const endpointDef = Object.values(backend.endpoints)[0];
146+
expect(endpointDef).to.not.equal(undefined);
147+
if (endpointDef) {
148+
expect(endpointDef.func.id).to.equal("func");
149+
expect(endpointDef.func.project).to.equal("project");
150+
expect(endpointDef.func.region).to.equal("us-central1");
151+
expect(endpointDef.func.maxInstances).to.equal(42);
152+
expect(endpointDef.func.minInstances).to.equal(1);
153+
expect(endpointDef.func.serviceAccount).to.equal("service-account-1@");
154+
expect(
155+
"httpsTrigger" in endpointDef.func ? endpointDef.func.httpsTrigger.invoker : []
156+
).to.have.members(["service-account-2@", "service-account-3@"]);
157+
}
158+
});
113159
});

0 commit comments

Comments
 (0)