|
1 | 1 | CloudFormation do |
2 | 2 |
|
3 | | - Description "#{component_name} - #{component_version}" |
4 | | - |
5 | 3 | Condition("EnableReader", FnEquals(Ref("EnableReader"), 'true')) |
6 | 4 | Condition("UseUsernameAndPassword", FnEquals(Ref(:SnapshotID), '')) |
7 | 5 | Condition("UseSnapshotID", FnNot(FnEquals(Ref(:SnapshotID), ''))) |
8 | 6 |
|
9 | | - az_conditions_resources('SubnetPersistence', maximum_availability_zones) |
10 | | - |
11 | | - tags = [] |
12 | | - tags << { Key: 'Environment', Value: Ref(:EnvironmentName) } |
13 | | - tags << { Key: 'EnvironmentType', Value: Ref(:EnvironmentType) } |
| 7 | + aurora_tags = [] |
| 8 | + aurora_tags << { Key: 'Name', Value: FnSub("${EnvironmentName}-#{component_name}") } |
| 9 | + aurora_tags << { Key: 'Environment', Value: Ref(:EnvironmentName) } |
| 10 | + aurora_tags << { Key: 'EnvironmentType', Value: Ref(:EnvironmentType) } |
| 11 | + aurora_tags.push(*tags.map {|k,v| {Key: k, Value: FnSub(v)}}).uniq { |h| h[:Key] } if defined? tags |
14 | 12 |
|
15 | | - extra_tags.each { |key,value| tags << { Key: key, Value: value } } if defined? extra_tags |
| 13 | + ingress = [] |
| 14 | + security_group_rules.each do |rule| |
| 15 | + sg_rule = { |
| 16 | + FromPort: cluster_port, |
| 17 | + IpProtocol: 'TCP', |
| 18 | + ToPort: cluster_port, |
| 19 | + } |
| 20 | + if rule['security_group_id'] |
| 21 | + sg_rule['SourceSecurityGroupId'] = FnSub(rule['security_group_id']) |
| 22 | + else |
| 23 | + sg_rule['CidrIp'] = FnSub(rule['ip']) |
| 24 | + end |
| 25 | + if rule['desc'] |
| 26 | + sg_rule['Description'] = FnSub(rule['desc']) |
| 27 | + end |
| 28 | + ingress << sg_rule |
| 29 | + end if defined?(security_group_rules) |
16 | 30 |
|
17 | 31 | EC2_SecurityGroup(:SecurityGroup) do |
18 | 32 | VpcId Ref('VPCId') |
19 | | - GroupDescription FnJoin(' ', [ Ref(:EnvironmentName), component_name, 'security group' ]) |
20 | | - SecurityGroupIngress sg_create_rules(security_group, ip_blocks) |
21 | | - Tags tags + [{ Key: 'Name', Value: FnJoin('-', [ Ref(:EnvironmentName), component_name, 'security-group' ])}] |
| 33 | + GroupDescription FnSub("Aurora postgres #{component_name} access for the ${EnvironmentName} environment") |
| 34 | + SecurityGroupIngress ingress if ingress.any? |
| 35 | + SecurityGroupEgress ([ |
| 36 | + { |
| 37 | + CidrIp: "0.0.0.0/0", |
| 38 | + Description: "outbound all for ports", |
| 39 | + IpProtocol: -1, |
| 40 | + } |
| 41 | + ]) |
| 42 | + Tags aurora_tags |
22 | 43 | end |
23 | 44 |
|
24 | 45 | RDS_DBSubnetGroup(:DBClusterSubnetGroup) { |
25 | | - SubnetIds az_conditional_resources('SubnetPersistence', maximum_availability_zones) |
26 | | - DBSubnetGroupDescription FnJoin(' ', [ Ref(:EnvironmentName), component_name, 'subnet group' ]) |
27 | | - Tags tags + [{ Key: 'Name', Value: FnJoin('-', [ Ref(:EnvironmentName), component_name, 'subnet-group' ])}] |
| 46 | + SubnetIds Ref('SubnetIds') |
| 47 | + DBSubnetGroupDescription FnSub("Aurora postgres #{component_name} subnets for the ${EnvironmentName} environment") |
| 48 | + Tags aurora_tags |
28 | 49 | } |
29 | 50 |
|
30 | 51 | RDS_DBClusterParameterGroup(:DBClusterParameterGroup) { |
31 | | - Description FnJoin(' ', [ Ref(:EnvironmentName), component_name, 'cluster parameter group' ]) |
32 | | - Family 'aurora-postgresql9.6' |
| 52 | + Description FnSub("Aurora postgres #{component_name} cluster parameters for the ${EnvironmentName} environment") |
| 53 | + Family family |
33 | 54 | Parameters cluster_parameters if defined? cluster_parameters |
34 | | - Tags tags + [{ Key: 'Name', Value: FnJoin('-', [ Ref(:EnvironmentName), component_name, 'cluster-parameter-group' ])}] |
| 55 | + Tags aurora_tags |
35 | 56 | } |
36 | 57 |
|
37 | 58 | RDS_DBCluster(:DBCluster) { |
38 | 59 | Engine 'aurora-postgresql' |
| 60 | + EngineVersion engine_version if defined? engine_version |
39 | 61 | DBClusterParameterGroupName Ref(:DBClusterParameterGroup) |
40 | 62 | SnapshotIdentifier Ref(:SnapshotID) |
41 | 63 | SnapshotIdentifier FnIf('UseSnapshotID',Ref(:SnapshotID), Ref('AWS::NoValue')) |
42 | 64 | MasterUsername FnIf('UseUsernameAndPassword', FnJoin('', [ '{{resolve:ssm:', FnSub(master_login['username_ssm_param']), ':1}}' ]), Ref('AWS::NoValue')) |
43 | 65 | MasterUserPassword FnIf('UseUsernameAndPassword', FnJoin('', [ '{{resolve:ssm-secure:', FnSub(master_login['password_ssm_param']), ':1}}' ]), Ref('AWS::NoValue')) |
44 | 66 | DBSubnetGroupName Ref(:DBClusterSubnetGroup) |
45 | 67 | VpcSecurityGroupIds [ Ref(:SecurityGroup) ] |
| 68 | + StorageEncrypted storage_encrypted if defined? storage_encrypted |
| 69 | + KmsKeyId Ref('KmsKeyId') if (defined? kms) && (kms) |
46 | 70 | Port cluster_port |
47 | | - Tags tags + [{ Key: 'Name', Value: FnJoin('-', [ Ref(:EnvironmentName), component_name, 'cluster' ])}] |
| 71 | + Tags aurora_tags |
48 | 72 | } |
49 | 73 |
|
50 | 74 | RDS_DBParameterGroup(:DBInstanceParameterGroup) { |
51 | | - Description FnJoin(' ', [ Ref(:EnvironmentName), component_name, 'instance parameter group' ]) |
52 | | - Family 'aurora-postgresql9.6' |
| 75 | + Description FnSub("Aurora postgres #{component_name} instance parameters for the ${EnvironmentName} environment") |
| 76 | + Family family |
53 | 77 | Parameters instance_parameters if defined? instance_parameters |
54 | | - Tags tags + [{ Key: 'Name', Value: FnJoin('-', [ Ref(:EnvironmentName), component_name, 'instance-parameter-group' ])}] |
| 78 | + Tags aurora_tags |
55 | 79 | } |
56 | 80 |
|
57 | 81 | RDS_DBInstance(:DBClusterInstanceWriter) { |
58 | 82 | DBSubnetGroupName Ref(:DBClusterSubnetGroup) |
59 | 83 | DBParameterGroupName Ref(:DBInstanceParameterGroup) |
60 | 84 | DBClusterIdentifier Ref(:DBCluster) |
61 | 85 | Engine 'aurora-postgresql' |
| 86 | + EngineVersion engine_version if defined? engine_version |
62 | 87 | PubliclyAccessible 'false' |
63 | 88 | DBInstanceClass Ref(:WriterInstanceType) |
64 | | - Tags tags + [{ Key: 'Name', Value: FnJoin('-', [ Ref(:EnvironmentName), component_name, 'writer-instance' ])}] |
| 89 | + Tags aurora_tags |
65 | 90 | } |
66 | 91 |
|
67 | 92 | RDS_DBInstance(:DBClusterInstanceReader) { |
|
70 | 95 | DBParameterGroupName Ref(:DBInstanceParameterGroup) |
71 | 96 | DBClusterIdentifier Ref(:DBCluster) |
72 | 97 | Engine 'aurora-postgresql' |
| 98 | + EngineVersion engine_version if defined? engine_version |
73 | 99 | PubliclyAccessible 'false' |
74 | 100 | DBInstanceClass Ref(:ReaderInstanceType) |
75 | | - Tags tags + [{ Key: 'Name', Value: FnJoin('-', [ Ref(:EnvironmentName), component_name, 'reader-instance' ])}] |
| 101 | + Tags aurora_tags |
| 102 | + } |
| 103 | + |
| 104 | + Route53_RecordSet(:DBClusterReaderRecord) { |
| 105 | + Condition(:EnableReader) |
| 106 | + HostedZoneName FnJoin('', [ Ref('EnvironmentName'), '.', Ref('DnsDomain'), '.']) |
| 107 | + Name FnJoin('', [ hostname_read_endpoint, '.', Ref('EnvironmentName'), '.', Ref('DnsDomain'), '.' ]) |
| 108 | + Type 'CNAME' |
| 109 | + TTL '60' |
| 110 | + ResourceRecords [ FnGetAtt('DBCluster','ReadEndpoint.Address') ] |
76 | 111 | } |
77 | 112 |
|
78 | 113 | Route53_RecordSet(:DBHostRecord) { |
|
0 commit comments