1
1
resource "aws_cloudwatch_metric_alarm" "cache_cpu" {
2
- count = var. enabled ? 1 : 0
2
+ count = var. enabled ? local . num_nodes : 0
3
3
4
- alarm_name = " ${ local . cluster_id } -cpu-utilization"
4
+ alarm_name = " ${ tolist (aws_elasticache_replication_group . this [ 0 ] . member_clusters )[ count . index ] } -cpu-utilization"
5
5
alarm_description = " Redis cluster CPU utilization"
6
6
7
7
comparison_operator = " GreaterThanThreshold"
@@ -18,7 +18,7 @@ resource "aws_cloudwatch_metric_alarm" "cache_cpu" {
18
18
threshold = var. alarm_cpu_threshold_percent
19
19
20
20
dimensions = {
21
- CacheClusterId = local.cluster_id
21
+ CacheClusterId = tolist (aws_elasticache_replication_group . this [ 0 ] . member_clusters )[count.index]
22
22
}
23
23
24
24
alarm_actions = var. alarm_actions
@@ -30,9 +30,9 @@ resource "aws_cloudwatch_metric_alarm" "cache_cpu" {
30
30
}
31
31
32
32
resource "aws_cloudwatch_metric_alarm" "cache_memory" {
33
- count = var. enabled ? 1 : 0
33
+ count = var. enabled ? local . num_nodes : 0
34
34
35
- alarm_name = " ${ local . cluster_id } -freeable-memory"
35
+ alarm_name = " ${ tolist (aws_elasticache_replication_group . this [ 0 ] . member_clusters )[ count . index ] } -freeable-memory"
36
36
alarm_description = " Redis cluster freeable memory"
37
37
38
38
comparison_operator = " LessThanThreshold"
@@ -49,7 +49,7 @@ resource "aws_cloudwatch_metric_alarm" "cache_memory" {
49
49
tags = var. tags
50
50
51
51
dimensions = {
52
- CacheClusterId = local.cluster_id
52
+ CacheClusterId = tolist (aws_elasticache_replication_group . this [ 0 ] . member_clusters )[count.index]
53
53
}
54
54
55
55
alarm_actions = var. alarm_actions
0 commit comments