forked from terraform-aws-modules/terraform-aws-sqs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom.tf
More file actions
108 lines (89 loc) · 3.47 KB
/
Copy pathcustom.tf
File metadata and controls
108 lines (89 loc) · 3.47 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
variable "alarm_sns_topic_name" {
type = string
default = "chatops-info-alerts"
}
variable "create_msg_count_alarm" {
type = bool
default = false
}
variable "oldest_msg_to_alarm" {
type = number
default = 60 # 1 hr
description = "The number of minutes to wait before triggering the alarm"
}
variable "max_count_msg_to_alarm" {
type = number
default = 1000
description = "The number of messages to wait before triggering the alarm"
}
locals {
alarm_sns_topic_arn = "arn:aws:sns:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:${var.alarm_sns_topic_name}"
}
resource "aws_cloudwatch_metric_alarm" "sqs_oldest_msg_alarm" {
count = var.create ? 1 : 0
alarm_name = "${aws_sqs_queue.this.name}-sqs_oldest_msg_alarm"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "10"
metric_name = "ApproximateAgeOfOldestMessage"
namespace = "AWS/SQS"
period = "60"
statistic = "Average"
threshold = tostring(var.oldest_msg_to_alarm * 60)
alarm_description = "will trigger if the queue has any msg older than threshold minutes"
treat_missing_data = "missing"
alarm_actions = [local.alarm_sns_topic_arn]
dimensions = {
QueueName = aws_sqs_queue.this.name
}
}
resource "aws_cloudwatch_metric_alarm" "dlq_oldest_msg_alarm" {
count = var.create && var.create_dlq && var.create_msg_count_alarm ? 1 : 0
alarm_name = "${aws_sqs_queue.dlq.name}-dlq-sqs_msg_count_alarm"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "5"
metric_name = "ApproximateNumberOfMessagesVisible"
namespace = "AWS/SQS"
period = "60"
statistic = "Maximum"
threshold = tostring(var.oldest_msg_to_alarm * 60)
alarm_description = "will trigger if the queue has any msg older than threshold minutes"
treat_missing_data = "missing"
alarm_actions = [local.alarm_sns_topic_arn]
dimensions = {
QueueName = aws_sqs_queue.dlq.name
}
}
resource "aws_cloudwatch_metric_alarm" "sqs_count_msg_alarm" {
count = var.create && var.create_msg_count_alarm ? 1 : 0
alarm_name = "${aws_sqs_queue.dlq.name}-dlq-sqs_msg_count_alarm"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "5"
metric_name = "ApproximateNumberOfMessagesVisible"
namespace = "AWS/SQS"
period = "60"
statistic = "Maximum"
threshold = tostring(var.max_count_msg_to_alarm)
alarm_description = "will trigger if the queue has any msg older than threshold minutes"
treat_missing_data = "missing"
alarm_actions = [local.alarm_sns_topic_arn]
dimensions = {
QueueName = aws_sqs_queue.dlq.name
}
}
resource "aws_cloudwatch_metric_alarm" "dlq_count_msg_alarm" {
count = var.create && var.create_dlq ? 1 : 0
alarm_name = "${aws_sqs_queue.dlq.name}-dlq-sqs_oldest_msg_alarm"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "5"
metric_name = "ApproximateAgeOfOldestMessage"
namespace = "AWS/SQS"
period = "60"
statistic = "Maximum"
threshold = tostring(var.max_count_msg_to_alarm)
alarm_description = "will trigger if the queue has any msg older than threshold minutes"
treat_missing_data = "missing"
alarm_actions = [local.alarm_sns_topic_arn]
dimensions = {
QueueName = aws_sqs_queue.dlq.name
}
}