Skip to content

Commit e890009

Browse files
committed
add the ability to define vpcConnector
1 parent 1c15ac3 commit e890009

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

package/lib/compileFunctions.js

+5
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ module.exports = {
4848
funcObject.environment // eslint-disable-line comma-dangle
4949
);
5050

51+
if (_.get(funcObject, 'vpcConnector') || _.get(this, 'serverless.service.provider.vpcConnector')) {
52+
funcTemplate.properties.vpcConnector = _.get(funcObject, 'vpcConnector')
53+
|| _.get(this, 'serverless.service.provider.vpcConnector');
54+
}
55+
5156
if (!_.size(funcTemplate.properties.environmentVariables)) {
5257
delete funcTemplate.properties.environmentVariables;
5358
}

package/lib/compileFunctions.test.js

+72
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,78 @@ describe('CompileFunctions', () => {
440440
});
441441
});
442442

443+
it('should set the vpcConnector based on the function configuration', () => {
444+
googlePackage.serverless.service.functions = {
445+
func1: {
446+
handler: 'func1',
447+
vpcConnector: 'projects/PROJECT_ID/locations/us-central1/connectors/my-connector',
448+
events: [
449+
{ http: 'foo' },
450+
],
451+
},
452+
};
453+
454+
const compiledResources = [{
455+
type: 'cloudfunctions.v1beta2.function',
456+
name: 'my-service-dev-func1',
457+
properties: {
458+
location: 'us-central1',
459+
runtime: 'nodejs8',
460+
function: 'func1',
461+
availableMemoryMb: 256,
462+
vpcConnector: 'projects/PROJECT_ID/locations/us-central1/connectors/my-connector',
463+
timeout: '60s',
464+
sourceArchiveUrl: 'gs://sls-my-service-dev-12345678/some-path/artifact.zip',
465+
httpsTrigger: {
466+
url: 'foo',
467+
},
468+
labels: {},
469+
},
470+
}];
471+
472+
return googlePackage.compileFunctions().then(() => {
473+
expect(consoleLogStub.calledOnce).toEqual(true);
474+
expect(googlePackage.serverless.service.provider.compiledConfigurationTemplate.resources)
475+
.toEqual(compiledResources);
476+
});
477+
});
478+
479+
it('should set the vpcConnector based on the provider configuration', () => {
480+
googlePackage.serverless.service.functions = {
481+
func1: {
482+
handler: 'func1',
483+
events: [
484+
{ http: 'foo' },
485+
],
486+
},
487+
};
488+
googlePackage.serverless.service.provider.vpcConnector = 'projects/PROJECT_ID/locations/us-central1/connectors/my-connector';
489+
490+
const compiledResources = [{
491+
type: 'cloudfunctions.v1beta2.function',
492+
name: 'my-service-dev-func1',
493+
properties: {
494+
location: 'us-central1',
495+
runtime: 'nodejs8',
496+
function: 'func1',
497+
availableMemoryMb: 256,
498+
vpcConnector: 'projects/PROJECT_ID/locations/us-central1/connectors/my-connector',
499+
timeout: '60s',
500+
sourceArchiveUrl: 'gs://sls-my-service-dev-12345678/some-path/artifact.zip',
501+
httpsTrigger: {
502+
url: 'foo',
503+
},
504+
labels: {},
505+
},
506+
}];
507+
508+
return googlePackage.compileFunctions().then(() => {
509+
expect(consoleLogStub.calledOnce).toEqual(true);
510+
expect(googlePackage.serverless.service.provider.compiledConfigurationTemplate.resources)
511+
.toEqual(compiledResources);
512+
});
513+
});
514+
443515
it('should compile "http" events properly', () => {
444516
googlePackage.serverless.service.functions = {
445517
func1: {

0 commit comments

Comments
 (0)