Skip to content

Instantly share code, notes, and snippets.

@katesclau
Last active January 17, 2017 18:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save katesclau/8ece51b65736d0977ae53587d5b01903 to your computer and use it in GitHub Desktop.
Save katesclau/8ece51b65736d0977ae53587d5b01903 to your computer and use it in GitHub Desktop.
# 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