Last active
January 17, 2017 18:58
-
-
Save katesclau/8ece51b65736d0977ae53587d5b01903 to your computer and use it in GitHub Desktop.
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
# Policy and Alarm for high usage | |
resource "aws_autoscaling_policy" "up_policy" { | |
name = "${var.cluster_name}-up-policy" | |
scaling_adjustment = 1 | |
adjustment_type = "ChangeInCapacity" | |
cooldown = 300 | |
autoscaling_group_name = "${aws_autoscaling_group.asg.name}" | |
} | |
resource "aws_cloudwatch_metric_alarm" "high" { | |
alarm_name = "terraform-test-foobar5" | |
comparison_operator = "GreaterThanOrEqualToThreshold" | |
evaluation_periods = "2" | |
metric_name = "CPUUtilization" | |
namespace = "AWS/EC2" | |
period = "120" | |
statistic = "Average" | |
threshold = "${var.high_threshold}" | |
dimensions { | |
AutoScalingGroupName = "${aws_autoscaling_group.asg.name}" | |
} | |
alarm_description = "High CPU utilization on ${var.cluster_name} cluster" | |
alarm_actions = ["${aws_autoscaling_policy.up_policy.arn}"] | |
} | |
# Policy and Alarm for low usage | |
resource "aws_autoscaling_policy" "down_policy" { | |
name = "${var.cluster_name}-down-policy" | |
scaling_adjustment = -1 | |
adjustment_type = "ChangeInCapacity" | |
cooldown = 300 | |
autoscaling_group_name = "${aws_autoscaling_group.asg.name}" | |
} | |
resource "aws_cloudwatch_metric_alarm" "low" { | |
alarm_name = "terraform-test-foobar5" | |
comparison_operator = "LessThanOrEqualToThreshold" | |
evaluation_periods = "2" | |
metric_name = "CPUUtilization" | |
namespace = "AWS/EC2" | |
period = "120" | |
statistic = "Average" | |
threshold = "${var.low_threshold}" | |
dimensions { | |
AutoScalingGroupName = "${aws_autoscaling_group.asg.name}" | |
} | |
alarm_description = "Low CPU utilization on ${var.cluster_name} cluster" | |
alarm_actions = ["${aws_autoscaling_policy.down_policy.arn}"] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment