|
| 1 | +CloudFormation do |
| 2 | + |
| 3 | + Condition(:FailOver, FnNot(FnEquals(Ref(:CacheClusters), '1'))) |
| 4 | + Condition(:Cluster, FnEquals(Ref(:Cluster), 'true')) |
| 5 | + az_conditions_resources('SubnetCache', maximum_availability_zones) |
| 6 | + |
| 7 | + tags = [] |
| 8 | + tags << { Key: 'Environment', Value: Ref(:EnvironmentName) } |
| 9 | + tags << { Key: 'EnvironmentType', Value: Ref(:EnvironmentType) } |
| 10 | + |
| 11 | + extra_tags.each { |key,value| tags << { Key: key, Value: value } } if defined? extra_tags |
| 12 | + |
| 13 | + EC2_SecurityGroup(:SecurityGroupRedis) do |
| 14 | + VpcId Ref('VPCId') |
| 15 | + GroupDescription FnJoin(' ', [ Ref(:EnvironmentName), component_name, 'security group' ]) |
| 16 | + SecurityGroupIngress sg_create_rules(security_groups, ip_blocks) |
| 17 | + Tags tags + [{ Key: 'Name', Value: FnJoin('-', [ Ref(:EnvironmentName), component_name, 'security-group' ])}] |
| 18 | + end |
| 19 | + |
| 20 | + ElastiCache_SubnetGroup(:RedisSubnetGroup) { |
| 21 | + Description FnJoin('',[ Ref(:EnvironmentName), 'redis parameter group'] ) |
| 22 | + SubnetIds az_conditional_resources('SubnetCache', maximum_availability_zones) |
| 23 | + } |
| 24 | + |
| 25 | + ElastiCache_ParameterGroup(:RedisParameterGroup) { |
| 26 | + CacheParameterGroupFamily family |
| 27 | + Description FnJoin(' ',[ Ref(:EnvironmentName), component_name, 'parameter group'] ) |
| 28 | + Properties parameters if defined? parameters |
| 29 | + } |
| 30 | + |
| 31 | + cluster_parameters = { 'cluster-enabled': 'yes' } |
| 32 | + cluster_parameters.merge!(parameters) if defined? parameters |
| 33 | + |
| 34 | + ElastiCache_ParameterGroup(:RedisClusterParameterGroup) { |
| 35 | + CacheParameterGroupFamily family |
| 36 | + Description FnJoin(' ',[ Ref(:EnvironmentName), component_name, 'parameter group'] ) |
| 37 | + Properties cluster_parameters |
| 38 | + } |
| 39 | + |
| 40 | + ElastiCache_ReplicationGroup(:RedisReplicationGroup) { |
| 41 | + DependsOn ["RedisSubnetGroup"] |
| 42 | + |
| 43 | + ReplicationGroupDescription FnJoin(' ',[ Ref(:EnvironmentName), component_name, 'replication group'] ) |
| 44 | + |
| 45 | + Engine 'redis' |
| 46 | + EngineVersion engine_version if defined? engine_version |
| 47 | + AutoMinorVersionUpgrade minor_upgrade || true |
| 48 | + Port redis_port if defined? redis_port |
| 49 | + CacheNodeType Ref(:CacheInstanceType) |
| 50 | + CacheParameterGroupName FnIf(:Cluster, Ref(:RedisClusterParameterGroup), Ref(:RedisParameterGroup)) |
| 51 | + CacheSubnetGroupName Ref(:RedisSubnetGroup) |
| 52 | + SecurityGroupIds [ Ref(:SecurityGroupRedis) ] |
| 53 | + |
| 54 | + Property('AtRestEncryptionEnabled', encrypt) if defined? encrypt |
| 55 | + |
| 56 | + # AuthToken 'String' |
| 57 | + # TransitEncryptionEnabled true |
| 58 | + |
| 59 | + AutomaticFailoverEnabled FnIf(:FailOver, true, false) |
| 60 | + NumCacheClusters Ref(:CacheClusters) |
| 61 | + |
| 62 | + NumNodeGroups FnIf(:Cluster, Ref(:NumNodeGroups), 1) |
| 63 | + ReplicasPerNodeGroup FnIf(:Cluster, Ref(:ReplicasPerNodeGroup), 0) |
| 64 | + |
| 65 | + SnapshotArns [ Ref(:S3Snapshot) ] if restore_from_s3 |
| 66 | + SnapshotName Ref(:Snapshot) if restore_from_snapshot |
| 67 | + SnapshotWindow snapshot_window if defined? snapshot_window |
| 68 | + SnapshotRetentionLimit Ref(:SnapshotRetentionLimit) |
| 69 | + PreferredMaintenanceWindow maintenance_window if defined? maintenance_window |
| 70 | + Tags tags + [{ Key: 'Name', Value: FnJoin('-', [ Ref(:EnvironmentName), component_name, 'cache-cluster' ]) }] |
| 71 | + } |
| 72 | + |
| 73 | + record = (defined? dns_record ? "#{dns_record}" : 'redis') |
| 74 | + |
| 75 | + Route53_RecordSet(:RedisHostRecord) { |
| 76 | + HostedZoneName FnJoin('', [ Ref(:EnvironmentName), '.', Ref(:DnsDomain), '.']) |
| 77 | + Name FnJoin('', [record, '.', Ref(:EnvironmentName), '.', Ref(:DnsDomain), '.']) |
| 78 | + Type 'CNAME' |
| 79 | + TTL '60' |
| 80 | + ResourceRecords [ FnGetAtt(:RedisReplicationGroup,'PrimaryEndPoint.Address') ] |
| 81 | + } |
| 82 | + |
| 83 | +end |
0 commit comments