Skip to content
This repository has been archived by the owner on Dec 12, 2022. It is now read-only.

Commit

Permalink
fixing deprecated (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
Luca Venturelli authored Nov 27, 2017
1 parent 93ac804 commit 235b927
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 28 deletions.
5 changes: 3 additions & 2 deletions scaling/iam.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
resource "aws_iam_role" "ecs-autoscale-role" {
name = "ecs-scale-${terraform.env}-${var.cluster_name}-${var.service_name}"

assume_role_policy = <<EOF
{
"Version": "2012-10-17",
Expand All @@ -17,11 +18,11 @@ EOF
}

resource "aws_iam_role_policy_attachment" "ecs_autoscale" {
role = "${aws_iam_role.ecs-autoscale-role.id}"
role = "${aws_iam_role.ecs-autoscale-role.id}"
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceAutoscaleRole"
}

resource "aws_iam_role_policy_attachment" "ecs_cloudwatch" {
role = "${aws_iam_role.ecs-autoscale-role.id}"
role = "${aws_iam_role.ecs-autoscale-role.id}"
policy_arn = "arn:aws:iam::aws:policy/CloudWatchReadOnlyAccess"
}
50 changes: 30 additions & 20 deletions scaling/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ resource "aws_cloudwatch_metric_alarm" "ecs_service_scale_up_alarm" {
period = "${var.period_down}"
statistic = "${var.statistic}"
threshold = "${var.threshold_up}"

dimensions {
ClusterName = "${var.cluster_name}"
ServiceName = "${var.service_name}"
}

alarm_description = "This metric monitor ecs CPU utilization up"
alarm_actions = ["${aws_appautoscaling_policy.scale_up.arn}"]
}
Expand All @@ -24,10 +26,12 @@ resource "aws_cloudwatch_metric_alarm" "ecs_service_scale_down_alarm" {
period = "${var.period_down}"
statistic = "${var.statistic}"
threshold = "${var.threshold_down}"

dimensions {
ClusterName = "${var.cluster_name}"
ServiceName = "${var.service_name}"
}

alarm_description = "This metric monitor ecs CPU utilization down"
alarm_actions = ["${aws_appautoscaling_policy.scale_down.arn}"]
}
Expand All @@ -42,34 +46,40 @@ resource "aws_appautoscaling_target" "ecs_target" {
}

resource "aws_appautoscaling_policy" "scale_down" {
adjustment_type = "ChangeInCapacity"
cooldown = 60
metric_aggregation_type = "Maximum"
name = "${terraform.env}-${var.cluster_name}-${var.service_name}-scale-down"
resource_id = "service/${var.cluster_name}/${var.service_name}"
scalable_dimension = "ecs:service:DesiredCount"
service_namespace = "ecs"
name = "${terraform.env}-${var.cluster_name}-${var.service_name}-scale-down"
resource_id = "service/${var.cluster_name}/${var.service_name}"
scalable_dimension = "ecs:service:DesiredCount"
service_namespace = "ecs"

step_scaling_policy_configuration {
adjustment_type = "ChangeInCapacity"
cooldown = 60
metric_aggregation_type = "Maximum"

step_adjustment {
metric_interval_upper_bound = "${var.upperbound}"
scaling_adjustment = "${var.scale_down_adjustment}"
step_adjustment {
metric_interval_upper_bound = "${var.upperbound}"
scaling_adjustment = "${var.scale_down_adjustment}"
}
}

depends_on = ["aws_appautoscaling_target.ecs_target"]
}

resource "aws_appautoscaling_policy" "scale_up" {
adjustment_type = "ChangeInCapacity"
cooldown = 60
metric_aggregation_type = "Maximum"
name = "${terraform.env}-${var.cluster_name}-${var.service_name}-scale-up"
resource_id = "service/${var.cluster_name}/${var.service_name}"
scalable_dimension = "ecs:service:DesiredCount"
service_namespace = "ecs"
name = "${terraform.env}-${var.cluster_name}-${var.service_name}-scale-up"
resource_id = "service/${var.cluster_name}/${var.service_name}"
scalable_dimension = "ecs:service:DesiredCount"
service_namespace = "ecs"

step_scaling_policy_configuration {
adjustment_type = "ChangeInCapacity"
cooldown = 60
metric_aggregation_type = "Maximum"

step_adjustment {
metric_interval_lower_bound = "${var.lowerbound}"
scaling_adjustment = "${var.scale_up_adjustment}"
step_adjustment {
metric_interval_lower_bound = "${var.lowerbound}"
scaling_adjustment = "${var.scale_up_adjustment}"
}
}

depends_on = ["aws_appautoscaling_target.ecs_target"]
Expand Down
1 change: 1 addition & 0 deletions scaling/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

12 changes: 6 additions & 6 deletions scaling/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ variable "service_name" {
}

variable "evaluation_periods" {
default = "4"
default = "4"
}

variable "period_down" {
default = "120"
}

variable "period_up" {
default = "60"
default = "60"
}

variable "threshold_up" {
Expand All @@ -27,23 +27,23 @@ variable "threshold_down" {
}

variable "statistic" {
default = "Average"
default = "Average"
}

variable "min_capacity" {
default = "1"
}

variable "max_capacity" {
default = "4"
default = "4"
}

variable "lowerbound" {
default = "0"
default = "0"
}

variable "upperbound" {
default = "0"
default = "0"
}

variable "scale_up_adjustment" {
Expand Down

0 comments on commit 235b927

Please sign in to comment.