-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautoscaling-policy.tf
executable file
·62 lines (54 loc) · 1.81 KB
/
autoscaling-policy.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
59
60
61
62
/*
* Scale up alarm
*/
resource "aws_autoscaling_policy" "aws-cpu-policy" {
name = "aws-cpu-policy"
autoscaling_group_name = "${aws_autoscaling_group.aws.name}"
adjustment_type = "ChangeInCapacity"
scaling_adjustment = "1"
cooldown = "300"
policy_type = "SimpleScaling"
}
resource "aws_cloudwatch_metric_alarm" "aws-cpu-alarm" {
alarm_name = "aws-cpu-alarm"
alarm_description = "aws-cpu-alarm"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "2"
metric_name = "CPUUtilization"
namespace = "AWS/EC2"
period = "120"
statistic = "Average"
threshold = "60"
dimensions = {
"AutoScalingGroupName" = "${aws_autoscaling_group.aws.name}"
}
actions_enabled = true
alarm_actions = ["${aws_autoscaling_policy.aws-cpu-policy.arn}"]
}
/*
* Scale down alarm
*/
resource "aws_autoscaling_policy" "aws-cpu-policy-scaledown" {
name = "aws-cpu-policy-scaledown"
autoscaling_group_name = "${aws_autoscaling_group.aws.name}"
adjustment_type = "ChangeInCapacity"
scaling_adjustment = "-1"
cooldown = "300"
policy_type = "SimpleScaling"
}
resource "aws_cloudwatch_metric_alarm" "aws-cpu-alarm-scaledown" {
alarm_name = "aws-cpu-alarm-scaledown"
alarm_description = "aws-cpu-alarm-scaledown"
comparison_operator = "LessThanOrEqualToThreshold"
evaluation_periods = "2"
metric_name = "CPUUtilization"
namespace = "AWS/EC2"
period = "120"
statistic = "Average"
threshold = "50"
dimensions = {
"AutoScalingGroupName" = "${aws_autoscaling_group.aws.name}"
}
actions_enabled = true
alarm_actions = ["${aws_autoscaling_policy.aws-cpu-policy-scaledown.arn}"]
}