/
alarm.tf
34 lines (28 loc) · 907 Bytes
/
alarm.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
resource "aws_cloudwatch_metric_alarm" "canary_alarm" {
for_each = var.endpoints
alarm_name = "${each.key}-canary-alarm"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "1"
metric_name = "Failed"
namespace = "CloudWatchSynthetics"
period = "60" # 1 minute
statistic = "Sum"
threshold = "1"
treat_missing_data = "notBreaching"
dimensions = {
CanaryName = aws_synthetics_canary.canary[each.key].name
}
alarm_description = "Canary alarm for ${each.key}"
alarm_actions = [
aws_sns_topic.canary_alarm.arn
]
}
# #tfsec:ignore:aws-sns-enable-topic-encryption
resource "aws_sns_topic" "canary_alarm" {
name = "canary-alarm"
}
resource "aws_sns_topic_subscription" "canary_alarm" {
topic_arn = aws_sns_topic.canary_alarm.arn
protocol = "email"
endpoint = var.alarm_email
}