-
-
Notifications
You must be signed in to change notification settings - Fork 220
/
cloudwatch-alarm.tf
31 lines (25 loc) · 1009 Bytes
/
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
# 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]
dimensions = {
InstanceId = one(aws_instance.default[*].id)
}
alarm_actions = [
null_resource.check_alarm_action[count.index].triggers.action
]
}