forked from terraform-aws-modules/terraform-aws-autoscaling
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathautoscaling-rules.tf
63 lines (57 loc) · 2.64 KB
/
autoscaling-rules.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
63
# TODO: Add mem alarms/policies - Look at ecs_cluster
# Enable either one/both/none
# Need something that will work well for ECS
// CloudWatch Alarms
# TODO: look at changing to a submodule
# one module do high/low alarm and policies - Call for cpu, mem
# ?? modules for single alarm and policy
resource "aws_cloudwatch_metric_alarm" "high_cpu" {
count = "${var.enable_scaling_policies}"
alarm_name = "${title("ec2-asg-${var.name}-high-cpu-utilization")}"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "${var.scaling_policy_high_cpu_evaluation_periods}"
metric_name = "CPUUtilization"
namespace = "AWS/EC2"
period = "${var.scaling_policy_high_cpu_period}"
statistic = "Average"
threshold = "${var.scaling_policy_high_cpu_threshold}"
alarm_description = "This metric monitor ec2 high cpu utilization"
alarm_actions = ["${aws_autoscaling_policy.cpu_scaling_out.arn}"]
dimensions {
AutoScalingGroupName = "${aws_autoscaling_group.this.name}"
}
}
resource "aws_cloudwatch_metric_alarm" "low_cpu" {
count = "${var.enable_scaling_policies}"
alarm_name = "${title("ec2-asg-${var.name}-low-cpu-utilization")}"
comparison_operator = "LessThanThreshold"
evaluation_periods = "${var.scaling_policy_low_cpu_evaluation_periods}"
metric_name = "CPUUtilization"
namespace = "AWS/EC2"
period = "${var.scaling_policy_low_cpu_period}"
statistic = "Average"
threshold = "${var.scaling_policy_low_cpu_threshold}"
alarm_description = "This metric monitor ec2 low cpu utilization"
alarm_actions = ["${aws_autoscaling_policy.cpu_scaling_in.arn}"]
dimensions {
AutoScalingGroupName = "${aws_autoscaling_group.this.name}"
}
}
// Auto Scaling Policy
# TODO: look at changing to a submodule
resource "aws_autoscaling_policy" "cpu_scaling_out" {
count = "${var.enable_scaling_policies}"
name = "cpu-scaling-out"
scaling_adjustment = "${length(var.vpc_zone_identifier)}"
adjustment_type = "ChangeInCapacity"
cooldown = "${var.scaling_policy_scaling_out_cooldown}"
autoscaling_group_name = "${aws_autoscaling_group.this.name}"
}
resource "aws_autoscaling_policy" "cpu_scaling_in" {
count = "${var.enable_scaling_policies}"
name = "cpu-scaling-in"
scaling_adjustment = -1
adjustment_type = "ChangeInCapacity"
cooldown = "${var.scaling_policy_scaling_in_cooldown}"
autoscaling_group_name = "${aws_autoscaling_group.this.name}"
}