Skip to content

Commit 1148e2d

Browse files
committed
Allowing multiple SNS topics for alerting
1 parent eb0e2a0 commit 1148e2d

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

_variables.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ variable "asg_memory_target" {
7575
description = "Target average memory percentage to track for autoscaling"
7676
}
7777

78-
variable "alarm_sns_topic" {
79-
default = ""
80-
description = "Alarm topic to create and alert on ECS cluster metrics"
78+
variable "alarm_sns_topics" {
79+
default = []
80+
description = "Alarm topics to create and alert on ECS instance metrics"
8181
}

cloutwatch-alarms.tf

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
resource "aws_cloudwatch_metric_alarm" "high_memory" {
2-
count = "${var.alarm_sns_topic == "" ? 0 : 1}"
2+
count = "${length(var.alarm_sns_topics) > 0 ? 1 : 0}"
33

44
alarm_name = "${data.aws_iam_account_alias.current.account_alias}-ecs-${var.name}-high-memory"
55
comparison_operator = "GreaterThanOrEqualToThreshold"
@@ -10,15 +10,16 @@ resource "aws_cloudwatch_metric_alarm" "high_memory" {
1010
statistic = "Maximum"
1111
threshold = "80"
1212
alarm_description = "Cluster node memory above threshold"
13-
alarm_actions = ["${var.alarm_sns_topic}"]
13+
alarm_actions = var.alarm_sns_topics
14+
ok_actions = var.alarm_sns_topics
1415

1516
dimensions = {
1617
ClusterName = "${aws_ecs_cluster.ecs.name}"
1718
}
1819
}
1920

2021
resource "aws_cloudwatch_metric_alarm" "high_cpu" {
21-
count = "${var.alarm_sns_topic == "" ? 0 : 1}"
22+
count = "${length(var.alarm_sns_topics) > 0 ? 1 : 0}"
2223

2324
alarm_name = "${data.aws_iam_account_alias.current.account_alias}-ecs-${var.name}-high-cpu"
2425
comparison_operator = "GreaterThanOrEqualToThreshold"
@@ -29,7 +30,8 @@ resource "aws_cloudwatch_metric_alarm" "high_cpu" {
2930
statistic = "Maximum"
3031
threshold = "80"
3132
alarm_description = "Cluster node CPU above threshold"
32-
alarm_actions = ["${var.alarm_sns_topic}"]
33+
alarm_actions = var.alarm_sns_topics
34+
ok_actions = var.alarm_sns_topics
3335

3436
dimensions = {
3537
ClusterName = "${aws_ecs_cluster.ecs.name}"

0 commit comments

Comments
 (0)