|
| 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 |
0 commit comments