Skip to content
This repository has been archived by the owner on Dec 20, 2023. It is now read-only.

Added 'subnetGroup' option #65

Merged
merged 5 commits into from
Jun 3, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ custom:
services:
- kms
- secretsmanager

# optional
# can pick one of subnet groups in (rds / redshift / elasticache / dax)
# ex) DAX is not available in ap-northeast-2 so I don't want to make DAX subnet group
subnetGroup:
- rds
```

## CloudFormation Outputs
Expand Down
6 changes: 6 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class ServerlessVpcPlugin {
let createNatInstance = false;
let createBastionHost = false;
let bastionHostKeyName = null;
let subnetGroup = [];

const { vpcConfig } = this.serverless.service.custom;

Expand Down Expand Up @@ -70,6 +71,9 @@ class ServerlessVpcPlugin {
if (Array.isArray(vpcConfig.services)) {
services = vpcConfig.services.map(s => s.trim().toLowerCase());
}
if (Array.isArray(vpcConfig.subnetGroup) && vpcConfig.subnetGroup.length > 0) {
({ subnetGroup } = vpcConfig);
}

if ('createDbSubnet' in vpcConfig && typeof vpcConfig.createDbSubnet === 'boolean') {
({ createDbSubnet } = vpcConfig);
Expand Down Expand Up @@ -221,6 +225,8 @@ class ServerlessVpcPlugin {
if (createDbSubnet) {
if (numZones < 2) {
this.serverless.cli.log('WARNING: less than 2 AZs; skipping subnet group provisioning');
} else if (subnetGroup.length > 0) {
Object.assign(resources, buildSubnetGroups(numZones, subnetGroup));
} else {
Object.assign(resources, buildSubnetGroups(numZones));
}
Expand Down
14 changes: 13 additions & 1 deletion src/subnet_groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,22 @@ function buildDAXSubnetGroup(numZones = 0, { name = 'DAXSubnetGroup' } = {}) {
* @param {Number} numZones Number of availability zones
* @return {Object}
*/
function buildSubnetGroups(numZones = 0) {
function buildSubnetGroups(numZones = 0, subnetGroup = []) {
if (numZones < 2) {
return {};
}
const subnetGroups = {
rds: buildRDSSubnetGroup,
redshift: buildRedshiftSubnetGroup,
elasticache: buildElastiCacheSubnetGroup,
dax: buildDAXSubnetGroup,
}
if (subnetGroup.length > 0) {
return subnetGroup.reduce(function(acc, service) {
let builtSubnetGroup = subnetGroups[service.toLowerCase()](numZones);
return Object.assign(acc, builtSubnetGroup);
}, {});
}
return Object.assign(
{},
buildRDSSubnetGroup(numZones),
Expand Down