-
-
Notifications
You must be signed in to change notification settings - Fork 221
/
cloudwatch-alarm.tf
34 lines (27 loc) · 1.06 KB
/
cloudwatch-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
# Restart dead or hung instance
resource "null_resource" "check_alarm_action" {
count = var.disable_alarm_action ? 0 : local.instance_count
triggers = {
action = "arn:${data.aws_partition.default.partition}:swf:${local.region}:${data.aws_caller_identity.default.account_id}:${var.default_alarm_action}"
}
}
resource "aws_cloudwatch_metric_alarm" "default" {
count = var.disable_alarm_action ? 0 : local.instance_count
alarm_name = module.this.id
comparison_operator = var.comparison_operator
evaluation_periods = var.evaluation_periods
metric_name = var.metric_name
namespace = var.metric_namespace
period = var.applying_period
statistic = var.statistic_level
threshold = var.metric_threshold
depends_on = [null_resource.check_alarm_action]
treat_missing_data = var.metric_treat_missing_data
dimensions = {
InstanceId = one(aws_instance.default[*].id)
}
alarm_actions = [
null_resource.check_alarm_action[count.index].triggers.action
]
tags = module.this.tags
}