Skip to content

Commit

Permalink
Merge pull request #196 from openaddresses/rds-vpc
Browse files Browse the repository at this point in the history
VPC RDS Instance
  • Loading branch information
ingalls authored Sep 16, 2021
2 parents 90c6f13 + 35fcdf7 commit 0dbe5ad
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 21 deletions.
10 changes: 6 additions & 4 deletions cloudformation/batch.template.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
'use strict';

const cf = require('@mapbox/cloudfriend');
const api = require('./api');
const batch = require('./batch');
const db = require('./db');
const schedule = require('./schedule');
const api = require('./lib/api');
const batch = require('./lib/batch');
const db = require('./lib/db');
const schedule = require('./lib/schedule');
const kms = require('./lib/kms');
const alarms = require('batch-alarms');

const stack = {
Expand Down Expand Up @@ -39,6 +40,7 @@ module.exports = cf.merge(
stack,
db,
api,
kms,
batch,
alarms({
prefix: 'Batch',
Expand Down
2 changes: 1 addition & 1 deletion cloudformation/api.js → cloudformation/lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ const stack = {
{ Name: 'MAPBOX_TOKEN', Value: cf.ref('MapboxToken') },
{ Name: 'MAILGUN_API_KEY', Value: cf.ref('MailGun') },
{ Name: 'OPENCOLLECTIVE_API_KEY', Value: cf.ref('OpenCollective') },
{ Name: 'POSTGRES', Value: cf.join(['postgresql://openaddresses:', cf.ref('DatabasePassword'), '@', cf.getAtt('DBInstance', 'Endpoint.Address'), ':5432/openaddresses']) },
{ Name: 'POSTGRES', Value: cf.join(['postgresql://openaddresses:', cf.ref('DatabasePassword'), '@', cf.getAtt('DBInstanceVPC', 'Endpoint.Address'), ':5432/openaddresses']) },
{ Name: 'SharedSecret', Value: cf.ref('SharedSecret') },
{ Name: 'GithubSecret', Value: cf.ref('GithubSecret') },
{ Name: 'Bucket', Value: cf.ref('Bucket') },
Expand Down
File renamed without changes.
36 changes: 20 additions & 16 deletions cloudformation/db.js → cloudformation/lib/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,41 @@ const stack = {
}
},
Resources: {
DBInstance: {
DBInstanceVPC: {
Type: 'AWS::RDS::DBInstance',
Properties: {
Engine: 'postgres',
DBName: 'openaddresses',
DBInstanceIdentifier: cf.stackName,
KmsKeyId: cf.ref('OAKMS'),
EngineVersion: '13.3',
MasterUsername: 'openaddresses',
MasterUserPassword: cf.ref('DatabasePassword'),
AllocatedStorage: 10,
MaxAllocatedStorage: 100,
BackupRetentionPeriod: 10,
StorageType: 'gp2',
StorageEncrypted: true,
DBInstanceClass: cf.ref('DatabaseType'),
DBSecurityGroups: [cf.ref('DBSecurityGroup')],
VPCSecurityGroups: [cf.ref('DBVPCSecurityGroup')],
DBSubnetGroupName: cf.ref('DBSubnet'),
PubliclyAccessible: true
}
},
DBVPCSecurityGroup: {
Type: 'AWS::EC2::SecurityGroup',
Properties: {
GroupDescription: cf.join('-', [cf.stackName, 'rds-sg']),
VpcId: 'vpc-3f2aa15a',
SecurityGroupIngress: [{
IpProtocol: '-1',
SourceSecurityGroupId: cf.getAtt('APIServiceSecurityGroup', 'GroupId')
},{
IpProtocol: '-1',
CidrIp: '0.0.0.0/0'
}]
}
},
DBSubnet: {
Type: 'AWS::RDS::DBSubnetGroup',
Properties: {
Expand All @@ -50,19 +67,6 @@ const stack = {
]
}
},
DBSecurityGroup: {
Type: 'AWS::RDS::DBSecurityGroup',
Properties: {
GroupDescription: cf.join('-', [cf.stackName, 'rds-sg']),
EC2VpcId: 'vpc-3f2aa15a',
DBSecurityGroupIngress: [{
EC2SecurityGroupId: cf.getAtt('APIServiceSecurityGroup', 'GroupId')
},{
CIDRIP: '0.0.0.0/0'
}]
}
}

},
Outputs: {
DB: {
Expand All @@ -72,7 +76,7 @@ const stack = {
':',
cf.ref('DatabasePassword'),
'@',
cf.getAtt('DBInstance', 'Endpoint.Address'),
cf.getAtt('DBInstanceVPC', 'Endpoint.Address'),
':5432/openaddresses'
])
}
Expand Down
29 changes: 29 additions & 0 deletions cloudformation/lib/kms.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

const cf = require('@mapbox/cloudfriend');

const stack = {
Resources: {
OAKMS: {
Type : 'AWS::KMS::Key',
Properties: {
Description: cf.stackName,
Enabled: true,
EnableKeyRotation: false,
KeyPolicy: {
Id: cf.stackName,
Statement: [{
Effect: 'Allow',
Principal: {
AWS: cf.join(['arn:aws:iam::', cf.accountId, ':root']),
},
Action: ['kms:*'],
Resource: '*'
}]
}
}
}
}
};

module.exports = stack;
File renamed without changes.
1 change: 1 addition & 0 deletions cloudformation/task.template.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const cf = require('@mapbox/cloudfriend');

const stack = {
AWSTemplateFormatVersion: '2010-09-09',
Description: 'OpenAddresses Batch T3 Compute Environment',
Expand Down

0 comments on commit 0dbe5ad

Please sign in to comment.