@@ -54,6 +54,7 @@ resource "aws_security_group_rule" "ingress_cidr_blocks" {
54
54
55
55
locals {
56
56
elasticache_subnet_group_name = var. elasticache_subnet_group_name != " " ? var. elasticache_subnet_group_name : join (" " , aws_elasticache_subnet_group. default . * . name )
57
+ elasticache_member_clusters = tolist (aws_elasticache_replication_group. default . member_clusters )
57
58
}
58
59
59
60
resource "aws_elasticache_subnet_group" "default" {
@@ -117,8 +118,8 @@ resource "aws_elasticache_replication_group" "default" {
117
118
# CloudWatch Resources
118
119
#
119
120
resource "aws_cloudwatch_metric_alarm" "cache_cpu" {
120
- count = var. enabled ? 1 : 0
121
- alarm_name = " ${ module . label . id } -cpu-utilization"
121
+ count = var. enabled ? length (local . elasticache_member_clusters ) : 0
122
+ alarm_name = " ${ element (local . elasticache_member_clusters , count . index ) } -cpu-utilization"
122
123
alarm_description = " Redis cluster CPU utilization"
123
124
comparison_operator = " GreaterThanThreshold"
124
125
evaluation_periods = " 1"
@@ -130,7 +131,7 @@ resource "aws_cloudwatch_metric_alarm" "cache_cpu" {
130
131
threshold = var. alarm_cpu_threshold_percent
131
132
132
133
dimensions = {
133
- CacheClusterId = module.label.id
134
+ CacheClusterId = element (local . elasticache_member_clusters , count . index )
134
135
}
135
136
136
137
alarm_actions = var. alarm_actions
@@ -139,8 +140,8 @@ resource "aws_cloudwatch_metric_alarm" "cache_cpu" {
139
140
}
140
141
141
142
resource "aws_cloudwatch_metric_alarm" "cache_memory" {
142
- count = var. enabled ? 1 : 0
143
- alarm_name = " ${ module . label . id } -freeable-memory"
143
+ count = var. enabled ? length (local . elasticache_member_clusters ) : 0
144
+ alarm_name = " ${ element (local . elasticache_member_clusters , count . index ) } -freeable-memory"
144
145
alarm_description = " Redis cluster freeable memory"
145
146
comparison_operator = " LessThanThreshold"
146
147
evaluation_periods = " 1"
@@ -152,7 +153,7 @@ resource "aws_cloudwatch_metric_alarm" "cache_memory" {
152
153
threshold = var. alarm_memory_threshold_bytes
153
154
154
155
dimensions = {
155
- CacheClusterId = module.label.id
156
+ CacheClusterId = element (local . elasticache_member_clusters , count . index )
156
157
}
157
158
158
159
alarm_actions = var. alarm_actions
0 commit comments