Skip to content

Commit 5632c2d

Browse files
authored
Merge pull request #1 from LewS/master
initial commit
2 parents 6676ecb + 57e010c commit 5632c2d

File tree

4 files changed

+134
-0
lines changed

4 files changed

+134
-0
lines changed

aurora-postgres.cfhighlander.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
CfhighlanderTemplate do
2+
DependsOn 'vpc@1.2.0'
3+
Parameters do
4+
ComponentParam 'EnvironmentName', 'dev', isGlobal: true
5+
ComponentParam 'EnvironmentType', 'development', isGlobal: true, allowedValues: ['development', 'production']
6+
ComponentParam 'StackOctet', isGlobal: true
7+
MappingParam('WriterInstanceType') do
8+
map 'EnvironmentType'
9+
attribute 'WriterInstanceType'
10+
end
11+
MappingParam('ReaderInstanceType') do
12+
map 'EnvironmentType'
13+
attribute 'ReaderInstanceType'
14+
end
15+
MappingParam('DnsDomain') do
16+
map 'AccountId'
17+
attribute 'DnsDomain'
18+
end
19+
maximum_availability_zones.times do |az|
20+
ComponentParam "SubnetPersistence#{az}"
21+
end
22+
ComponentParam 'SnapshotID'
23+
ComponentParam 'EnableReader', 'false'
24+
ComponentParam 'VPCId', type: 'AWS::EC2::VPC::Id'
25+
end
26+
end

aurora-postgres.cfndsl.rb

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
CloudFormation do
2+
3+
Description "#{component_name} - #{component_version}"
4+
5+
Condition("EnableReader", FnEquals(Ref("EnableReader"), 'true'))
6+
az_conditions_resources('SubnetPersistence', maximum_availability_zones)
7+
8+
tags = []
9+
tags << { Key: 'Environment', Value: Ref(:EnvironmentName) }
10+
tags << { Key: 'EnvironmentType', Value: Ref(:EnvironmentType) }
11+
12+
extra_tags.each { |key,value| tags << { Key: key, Value: value } } if defined? extra_tags
13+
14+
EC2_SecurityGroup(:SecurityGroup) do
15+
VpcId Ref('VPCId')
16+
GroupDescription FnJoin(' ', [ Ref(:EnvironmentName), component_name, 'security group' ])
17+
SecurityGroupIngress sg_create_rules(security_group, ip_blocks)
18+
Tags tags + [{ Key: 'Name', Value: FnJoin('-', [ Ref(:EnvironmentName), component_name, 'security-group' ])}]
19+
end
20+
21+
RDS_DBSubnetGroup(:DBClusterSubnetGroup) {
22+
SubnetIds az_conditional_resources('SubnetPersistence', maximum_availability_zones)
23+
DBSubnetGroupDescription FnJoin(' ', [ Ref(:EnvironmentName), component_name, 'subnet group' ])
24+
Tags tags + [{ Key: 'Name', Value: FnJoin('-', [ Ref(:EnvironmentName), component_name, 'subnet-group' ])}]
25+
}
26+
27+
RDS_DBClusterParameterGroup(:DBClusterParameterGroup) {
28+
Description FnJoin(' ', [ Ref(:EnvironmentName), component_name, 'cluster parameter group' ])
29+
Family 'aurora-postgresql'
30+
Parameters cluster_parameters if defined? cluster_parameters
31+
Tags tags + [{ Key: 'Name', Value: FnJoin('-', [ Ref(:EnvironmentName), component_name, 'cluster-parameter-group' ])}]
32+
}
33+
34+
RDS_DBCluster(:DBCluster) {
35+
Engine 'aurora-postgresql'
36+
DBClusterParameterGroupName Ref(:DBClusterParameterGroup)
37+
SnapshotIdentifier Ref(:SnapshotID)
38+
DBSubnetGroupName Ref(:DBClusterSubnetGroup)
39+
VpcSecurityGroupIds [ Ref(:SecurityGroup) ]
40+
Tags tags + [{ Key: 'Name', Value: FnJoin('-', [ Ref(:EnvironmentName), component_name, 'cluster' ])}]
41+
}
42+
43+
RDS_DBParameterGroup(:DBInstanceParameterGroup) {
44+
Description FnJoin(' ', [ Ref(:EnvironmentName), component_name, 'instance parameter group' ])
45+
Family 'aurora-postgresql9.6'
46+
Parameters instance_parameters if defined? instance_parameters
47+
Tags tags + [{ Key: 'Name', Value: FnJoin('-', [ Ref(:EnvironmentName), component_name, 'instance-parameter-group' ])}]
48+
}
49+
50+
RDS_DBInstance(:DBClusterInstanceWriter) {
51+
DBSubnetGroupName Ref(:DBClusterSubnetGroup)
52+
DBParameterGroupName Ref(:DBInstanceParameterGroup)
53+
DBClusterIdentifier Ref(:DBCluster)
54+
Engine 'aurora-postgresql'
55+
PubliclyAccessible 'false'
56+
DBInstanceClass Ref(:WriterInstanceType)
57+
Tags tags + [{ Key: 'Name', Value: FnJoin('-', [ Ref(:EnvironmentName), component_name, 'writer-instance' ])}]
58+
}
59+
60+
RDS_DBInstance(:DBClusterInstanceReader) {
61+
Condition(:EnableReader)
62+
DBSubnetGroupName Ref(:DBClusterSubnetGroup)
63+
DBParameterGroupName Ref(:DBInstanceParameterGroup)
64+
DBClusterIdentifier Ref(:DBCluster)
65+
Engine 'aurora-postgresql'
66+
PubliclyAccessible 'false'
67+
DBInstanceClass Ref(:ReaderInstanceType)
68+
Tags tags + [{ Key: 'Name', Value: FnJoin('-', [ Ref(:EnvironmentName), component_name, 'reader-instance' ])}]
69+
}
70+
71+
Route53_RecordSet(:DBHostRecord) {
72+
HostedZoneName FnJoin('', [ Ref('EnvironmentName'), '.', Ref('DnsDomain'), '.'])
73+
Name FnJoin('', [ hostname, '.', Ref('EnvironmentName'), '.', Ref('DnsDomain'), '.' ])
74+
Type 'CNAME'
75+
TTL '60'
76+
ResourceRecords [ FnGetAtt('DBCluster','Endpoint.Address') ]
77+
}
78+
79+
end

aurora-postgres.config.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
maximum_availability_zones: 5
2+
hostname: aurora2pg
3+
4+
cluster_parameters:
5+
6+
instance_parameters:
7+
8+
# Set `ip_blocks` here or export from vpc component
9+
ip_blocks:
10+
local:
11+
- 127.0.0.1/32
12+
13+
14+
security_group:
15+
-
16+
rules:
17+
-
18+
IpProtocol: tcp
19+
FromPort: 5432
20+
ToPort: 5432
21+
ips:
22+
- stack

aurora-postgres.mappings.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
EnvironmentType:
2+
development:
3+
WriterInstanceType: db.t2.micro
4+
ReaderInstanceType: db.t2.micro
5+
production:
6+
WriterInstanceType: db.t2.micro
7+
ReaderInstanceType: db.t2.micro

0 commit comments

Comments
 (0)