|
| 1 | +resource "aws_elasticache_replication_group" "lpa_redis" { |
| 2 | + automatic_failover_enabled = local.account.elasticache_count == 1 ? false : true |
| 3 | + engine = "redis" |
| 4 | + engine_version = "5.0.6" |
| 5 | + replication_group_id = "lpa-data-redis-${local.environment}" |
| 6 | + replication_group_description = "Replication Group for LPA Data" |
| 7 | + node_type = "cache.t2.small" |
| 8 | + number_cache_clusters = local.account.elasticache_count |
| 9 | + parameter_group_name = "default.redis5.0" |
| 10 | + port = 6379 |
| 11 | + subnet_group_name = "private-redis" |
| 12 | + security_group_ids = [aws_security_group.lpa_redis_sg.id] |
| 13 | + tags = local.default_tags |
| 14 | + apply_immediately = true |
| 15 | + |
| 16 | + lifecycle { |
| 17 | + ignore_changes = [number_cache_clusters] |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +resource "aws_security_group" "lpa_redis_sg" { |
| 22 | + name_prefix = "${local.environment}-redis-sg" |
| 23 | + vpc_id = local.account.vpc_id |
| 24 | + |
| 25 | + lifecycle { |
| 26 | + create_before_destroy = true |
| 27 | + } |
| 28 | + |
| 29 | + revoke_rules_on_delete = true |
| 30 | + |
| 31 | + tags = merge( |
| 32 | + local.default_tags, |
| 33 | + { |
| 34 | + "Name" = "${local.environment}-redis-sg" |
| 35 | + }, |
| 36 | + ) |
| 37 | +} |
| 38 | + |
| 39 | +locals { |
| 40 | + redis_rules = { |
| 41 | + cache_out = { |
| 42 | + port = 6379 |
| 43 | + type = "egress" |
| 44 | + protocol = "tcp" |
| 45 | + target_type = "self" |
| 46 | + target = true |
| 47 | + } |
| 48 | + cache_in = { |
| 49 | + port = 6379 |
| 50 | + type = "ingress" |
| 51 | + protocol = "tcp" |
| 52 | + target_type = "self" |
| 53 | + target = true |
| 54 | + } |
| 55 | + } |
| 56 | +} |
| 57 | + |
| 58 | +resource "aws_security_group_rule" "lpa_redis_rules" { |
| 59 | + for_each = local.redis_rules |
| 60 | + |
| 61 | + type = each.value.type |
| 62 | + protocol = each.value.protocol |
| 63 | + from_port = each.value.port |
| 64 | + to_port = each.value.port |
| 65 | + security_group_id = aws_security_group.lpa_redis_sg.id |
| 66 | + source_security_group_id = each.value.target_type == "security_group_id" ? each.value.target : null |
| 67 | + prefix_list_ids = each.value.target_type == "prefix_list_id" ? [each.value.target] : null |
| 68 | + description = each.key |
| 69 | + cidr_blocks = each.value.target_type == "cidr_block" ? [each.value.target] : null |
| 70 | + self = each.value.target_type == "self" ? each.value.target : null |
| 71 | +} |
0 commit comments