-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding alarms and scaling policies to enable autoscaling on the group
- Loading branch information
Showing
2 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
# AUTOSCALING POLICIES | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
# Scaling UP - CPU High | ||
resource "aws_autoscaling_policy" "cpu_high" { | ||
name = "${var.name_preffix}-cpu-high" | ||
autoscaling_group_name = "${aws_autoscaling_group.asg.name}" | ||
adjustment_type = "ChangeInCapacity" | ||
policy_type = "SimpleScaling" | ||
scaling_adjustment = "1" | ||
cooldown = "300" | ||
} | ||
# Scaling DOWN - CPU Low | ||
resource "aws_autoscaling_policy" "cpu_low" { | ||
name = "${var.name_preffix}-cpu-high" | ||
autoscaling_group_name = "${aws_autoscaling_group.asg.name}" | ||
adjustment_type = "ChangeInCapacity" | ||
policy_type = "SimpleScaling" | ||
scaling_adjustment = "-1" | ||
cooldown = "300" | ||
} | ||
|
||
# --------------------------------------------------------------------------------------------------------------------- | ||
# CLOUDWATCH METRIC ALARMS | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
resource "aws_cloudwatch_metric_alarm" "cpu_high_alarm" { | ||
alarm_name = "${var.name_preffix}-cpu-high-alarm" | ||
comparison_operator = "GreaterThanOrEqualToThreshold" | ||
evaluation_periods = "2" | ||
metric_name = "CPUUtilization" | ||
namespace = "AWS/EC2" | ||
period = "60" | ||
statistic = "Average" | ||
threshold = "80" | ||
actions_enabled = true | ||
alarm_actions = ["${aws_autoscaling_policy.cpu_high.arn}"] | ||
dimensions = { | ||
"AutoScalingGroupName" = "${aws_autoscaling_group.asg.name}" | ||
} | ||
} | ||
resource "aws_cloudwatch_metric_alarm" "cpu_low_alarm" { | ||
alarm_name = "${var.name_preffix}-cpu-low-alarm" | ||
comparison_operator = "LessThanOrEqualToThreshold" | ||
evaluation_periods = "2" | ||
metric_name = "CPUUtilization" | ||
namespace = "AWS/EC2" | ||
period = "60" | ||
statistic = "Average" | ||
threshold = "10" | ||
actions_enabled = true | ||
alarm_actions = ["${aws_autoscaling_policy.cpu_low.arn}"] | ||
dimensions = { | ||
"AutoScalingGroupName" = "${aws_autoscaling_group.asg.name}" | ||
} | ||
} |