-
Notifications
You must be signed in to change notification settings - Fork 0
/
autoscaling.tf
58 lines (48 loc) · 1.86 KB
/
autoscaling.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
resource "aws_autoscaling_policy" "scale_up" {
name = "${var.owner}_asg_scale_up"
scaling_adjustment = 1
adjustment_type = "ChangeInCapacity"
policy_type = "SimpleScaling"
cooldown = 300
autoscaling_group_name = module.eh_asg.this_autoscaling_group_name
}
resource "aws_autoscaling_policy" "scale_down" {
name = "${var.owner}_asg_scale_down"
scaling_adjustment = -1
adjustment_type = "ChangeInCapacity"
policy_type = "SimpleScaling"
cooldown = 600
autoscaling_group_name = module.eh_asg.this_autoscaling_group_name
}
resource "aws_cloudwatch_metric_alarm" "cpu_high" {
alarm_name = "${var.owner}_asg_cpu_utilization_high"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = 2
metric_name = "CPUUtilization"
namespace = "AWS/EC2"
period = 300
statistic = "Average"
threshold = 90
dimensions = {
AutoScalingGroupName = module.eh_asg.this_autoscaling_group_name
}
alarm_description = "Scale up if CPU utilization is above 90 for 300 seconds"
alarm_actions = [aws_autoscaling_policy.scale_up.arn]
tags = local.tags
}
resource "aws_cloudwatch_metric_alarm" "cpu_low" {
alarm_name = "${var.owner}_asg_cpu_utilization_low"
comparison_operator = "LessThanOrEqualToThreshold"
evaluation_periods = 2
metric_name = "CPUUtilization"
namespace = "AWS/EC2"
period = 600
statistic = "Average"
threshold = 10
dimensions = {
AutoScalingGroupName = module.eh_asg.this_autoscaling_group_name
}
alarm_description = "Scale down if the CPU utilization is below 10 for 600 seconds"
alarm_actions = [join("", aws_autoscaling_policy.scale_down.*.arn)]
tags = local.tags
}