Skip to content

Commit a6d3419

Browse files
pcboylaurenzlong
andauthored
Adds support for vpcConnector and vpcConnectorEgressSettings customization for functions (#2525)
Co-authored-by: Lauren Long <laurenzlong@users.noreply.github.com>
1 parent c40ebc8 commit a6d3419

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/deploy/functions/release.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,8 @@ module.exports = function(context, options, payload) {
258258
timeout: functionInfo.timeout,
259259
maxInstances: functionInfo.maxInstances,
260260
environmentVariables: defaultEnvVariables,
261+
vpcConnector: functionInfo.vpcConnector,
262+
vpcConnectorEgressSettings: functionInfo.vpcConnectorEgressSettings,
261263
})
262264
.then((createRes) => {
263265
if (_.has(functionTrigger, "httpsTrigger")) {
@@ -333,6 +335,8 @@ module.exports = function(context, options, payload) {
333335
timeout: functionInfo.timeout,
334336
runtime: runtime,
335337
maxInstances: functionInfo.maxInstances,
338+
vpcConnector: functionInfo.vpcConnector,
339+
vpcConnectorEgressSettings: functionInfo.vpcConnectorEgressSettings,
336340
environmentVariables: _.assign(
337341
{},
338342
existingFunction.environmentVariables,

src/gcp/cloudfunctions.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,25 @@ function _createFunction(options) {
6565
const location = "projects/" + options.projectId + "/locations/" + options.region;
6666
const func = location + "/functions/" + options.functionName;
6767
const endpoint = "/" + API_VERSION + "/" + location + "/functions";
68+
6869
const data = {
6970
sourceUploadUrl: options.sourceUploadUrl,
7071
name: func,
7172
entryPoint: options.entryPoint,
7273
labels: options.labels,
7374
runtime: options.runtime,
7475
};
76+
77+
if (options.vpcConnector) {
78+
data.vpcConnector = options.vpcConnector;
79+
// use implied project/location if only given connector id
80+
if (!data.vpcConnector.includes("/")) {
81+
data.vpcConnector = `${location}/connectors/${data.vpcConnector}`;
82+
}
83+
}
84+
if (options.vpcConnectorEgressSettings) {
85+
data.vpcConnectorEgressSettings = options.vpcConnectorEgressSettings;
86+
}
7587
if (options.availableMemoryMb) {
7688
data.availableMemoryMb = options.availableMemoryMb;
7789
}
@@ -143,6 +155,7 @@ function _updateFunction(options) {
143155
const location = "projects/" + options.projectId + "/locations/" + options.region;
144156
const func = location + "/functions/" + options.functionName;
145157
const endpoint = "/" + API_VERSION + "/" + func;
158+
146159
const data = _.assign(
147160
{
148161
sourceUploadUrl: options.sourceUploadUrl,
@@ -153,6 +166,18 @@ function _updateFunction(options) {
153166
);
154167
let masks = ["sourceUploadUrl", "name", "labels"];
155168

169+
if (options.vpcConnector) {
170+
data.vpcConnector = options.vpcConnector;
171+
// use implied project/location if only given connector id
172+
if (!data.vpcConnector.includes("/")) {
173+
data.vpcConnector = `${location}/connectors/${data.vpcConnector}`;
174+
}
175+
masks.push("vpcConnector");
176+
}
177+
if (options.vpcConnectorEgressSettings) {
178+
data.vpcConnectorEgressSettings = options.vpcConnectorEgressSettings;
179+
masks.push("vpcConnectorEgressSettings");
180+
}
156181
if (options.runtime) {
157182
data.runtime = options.runtime;
158183
masks = _.concat(masks, "runtime");

0 commit comments

Comments
 (0)