-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmain.tf
More file actions
85 lines (71 loc) · 2.8 KB
/
main.tf
File metadata and controls
85 lines (71 loc) · 2.8 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
# Create SNS topic for all email and external incident management tools notifications
resource "aws_sns_topic" "this" {
name = "${var.service_name}-monitoring"
# checkov:skip=CKV_AWS_26:SNS encryption for alerts is unnecessary
}
# Create CloudWatch alarms for the service
resource "aws_cloudwatch_metric_alarm" "high_app_http_5xx_count" {
alarm_name = "${var.service_name}-high-app-5xx-count"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = 5
metric_name = "HTTPCode_Target_5XX_Count"
namespace = "AWS/ApplicationELB"
period = 60
statistic = "Sum"
threshold = 1
alarm_description = "High HTTP service 5XX error count"
treat_missing_data = "notBreaching"
alarm_actions = [aws_sns_topic.this.arn]
ok_actions = [aws_sns_topic.this.arn]
dimensions = {
LoadBalancer = var.load_balancer_arn_suffix
}
}
resource "aws_cloudwatch_metric_alarm" "high_load_balancer_http_5xx_count" {
alarm_name = "${var.service_name}-high-load-balancer-5xx-count"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = 5
metric_name = "HTTPCode_ELB_5XX_Count"
namespace = "AWS/ApplicationELB"
period = 60
statistic = "Sum"
threshold = 1
alarm_description = "High HTTP ELB 5XX error count"
treat_missing_data = "notBreaching"
alarm_actions = [aws_sns_topic.this.arn]
ok_actions = [aws_sns_topic.this.arn]
dimensions = {
LoadBalancer = var.load_balancer_arn_suffix
}
}
resource "aws_cloudwatch_metric_alarm" "high_app_response_time" {
alarm_name = "${var.service_name}-high-app-response-time"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = 5
metric_name = "TargetResponseTime"
namespace = "AWS/ApplicationELB"
period = 60
statistic = "Average"
threshold = 0.2
alarm_description = "High target latency alert"
alarm_actions = [aws_sns_topic.this.arn]
ok_actions = [aws_sns_topic.this.arn]
dimensions = {
LoadBalancer = var.load_balancer_arn_suffix
}
}
#email integration
resource "aws_sns_topic_subscription" "email_integration" {
for_each = var.email_alert_recipients
topic_arn = aws_sns_topic.this.arn
protocol = "email"
endpoint = each.value
}
#External incident management service integration
resource "aws_sns_topic_subscription" "incident_management_service_integration" {
count = var.incident_management_service_integration_url != null ? 1 : 0
endpoint = var.incident_management_service_integration_url
endpoint_auto_confirms = true
protocol = "https"
topic_arn = aws_sns_topic.this.arn
}