-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update main.yml * Add files via upload * Add files via upload * Add files via upload
- Loading branch information
1 parent
123e041
commit 1b76717
Showing
4 changed files
with
199 additions
and
3 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
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,98 @@ | ||
# auto_scaling.tf | ||
|
||
resource "aws_appautoscaling_target" "ecs" { | ||
count = local.create_ecs_service | ||
service_namespace = "ecs" | ||
resource_id = "service/${aws_ecs_cluster.main.name}/${aws_ecs_service.main[count.index].name}" | ||
scalable_dimension = "ecs:service:DesiredCount" | ||
min_capacity = 1 | ||
max_capacity = 6 | ||
} | ||
|
||
# Automatically scale capacity up by one | ||
resource "aws_appautoscaling_policy" "up" { | ||
count = local.create_ecs_service | ||
name = "auto_scale_up" | ||
service_namespace = aws_appautoscaling_target.ecs[count.index].service_namespace | ||
resource_id = aws_appautoscaling_target.ecs[count.index].resource_id | ||
scalable_dimension = aws_appautoscaling_target.ecs[count.index].scalable_dimension | ||
|
||
step_scaling_policy_configuration { | ||
adjustment_type = "ChangeInCapacity" | ||
cooldown = 60 | ||
metric_aggregation_type = "Maximum" | ||
|
||
step_adjustment { | ||
metric_interval_lower_bound = 0 | ||
scaling_adjustment = 1 | ||
} | ||
} | ||
|
||
depends_on = [aws_appautoscaling_target.ecs] | ||
} | ||
|
||
# Automatically scale capacity down by one | ||
resource "aws_appautoscaling_policy" "down" { | ||
count = local.create_ecs_service | ||
name = "auto_scale_down" | ||
service_namespace = aws_appautoscaling_target.ecs[count.index].service_namespace | ||
resource_id = aws_appautoscaling_target.ecs[count.index].resource_id | ||
scalable_dimension = aws_appautoscaling_target.ecs[count.index].scalable_dimension | ||
|
||
step_scaling_policy_configuration { | ||
adjustment_type = "ChangeInCapacity" | ||
cooldown = 60 | ||
metric_aggregation_type = "Maximum" | ||
|
||
step_adjustment { | ||
metric_interval_upper_bound = 0 | ||
scaling_adjustment = -1 | ||
} | ||
} | ||
|
||
depends_on = [aws_appautoscaling_target.ecs] | ||
} | ||
|
||
# CloudWatch alarm that triggers the autoscaling up policy | ||
resource "aws_cloudwatch_metric_alarm" "service_memory_high" { | ||
count = local.create_ecs_service | ||
alarm_name = "ecs_memory_utilization_high_cdq" | ||
comparison_operator = "GreaterThanOrEqualToThreshold" | ||
evaluation_periods = "2" | ||
metric_name = "MemoryUtilization" | ||
namespace = "AWS/ECS" | ||
period = "30" | ||
statistic = "Average" | ||
threshold = "75" | ||
|
||
dimensions = { | ||
ClusterName = aws_ecs_cluster.main.name | ||
ServiceName = aws_ecs_service.main[count.index].name | ||
} | ||
|
||
alarm_actions = [aws_appautoscaling_policy.up[count.index].arn] | ||
|
||
tags = var.common_tags | ||
} | ||
|
||
# CloudWatch alarm that triggers the autoscaling down policy | ||
resource "aws_cloudwatch_metric_alarm" "service_memory_low" { | ||
count = local.create_ecs_service | ||
alarm_name = "ecs_memory_utilization_low_cdq" | ||
comparison_operator = "LessThanOrEqualToThreshold" | ||
evaluation_periods = "2" | ||
metric_name = "MemoryUtilization" | ||
namespace = "AWS/ECS" | ||
period = "30" | ||
statistic = "Average" | ||
threshold = "10" | ||
|
||
dimensions = { | ||
ClusterName = aws_ecs_cluster.main.name | ||
ServiceName = aws_ecs_service.main[count.index].name | ||
} | ||
|
||
alarm_actions = [aws_appautoscaling_policy.down[count.index].arn] | ||
|
||
tags = var.common_tags | ||
} |
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,98 @@ | ||
# auto_scaling.tf | ||
|
||
resource "aws_appautoscaling_target" "ecs" { | ||
count = local.create_ecs_service | ||
service_namespace = "ecs" | ||
resource_id = "service/${aws_ecs_cluster.main.name}/${aws_ecs_service.main[count.index].name}" | ||
scalable_dimension = "ecs:service:DesiredCount" | ||
min_capacity = 1 | ||
max_capacity = 6 | ||
} | ||
|
||
# Automatically scale capacity up by one | ||
resource "aws_appautoscaling_policy" "up" { | ||
count = local.create_ecs_service | ||
name = "auto_scale_up" | ||
service_namespace = aws_appautoscaling_target.ecs[count.index].service_namespace | ||
resource_id = aws_appautoscaling_target.ecs[count.index].resource_id | ||
scalable_dimension = aws_appautoscaling_target.ecs[count.index].scalable_dimension | ||
|
||
step_scaling_policy_configuration { | ||
adjustment_type = "ChangeInCapacity" | ||
cooldown = 60 | ||
metric_aggregation_type = "Maximum" | ||
|
||
step_adjustment { | ||
metric_interval_lower_bound = 0 | ||
scaling_adjustment = 1 | ||
} | ||
} | ||
|
||
depends_on = [aws_appautoscaling_target.ecs] | ||
} | ||
|
||
# Automatically scale capacity down by one | ||
resource "aws_appautoscaling_policy" "down" { | ||
count = local.create_ecs_service | ||
name = "auto_scale_down" | ||
service_namespace = aws_appautoscaling_target.ecs[count.index].service_namespace | ||
resource_id = aws_appautoscaling_target.ecs[count.index].resource_id | ||
scalable_dimension = aws_appautoscaling_target.ecs[count.index].scalable_dimension | ||
|
||
step_scaling_policy_configuration { | ||
adjustment_type = "ChangeInCapacity" | ||
cooldown = 60 | ||
metric_aggregation_type = "Maximum" | ||
|
||
step_adjustment { | ||
metric_interval_upper_bound = 0 | ||
scaling_adjustment = -1 | ||
} | ||
} | ||
|
||
depends_on = [aws_appautoscaling_target.ecs] | ||
} | ||
|
||
# CloudWatch alarm that triggers the autoscaling up policy | ||
resource "aws_cloudwatch_metric_alarm" "service_memory_high" { | ||
count = local.create_ecs_service | ||
alarm_name = "ecs_memory_utilization_high_cdq" | ||
comparison_operator = "GreaterThanOrEqualToThreshold" | ||
evaluation_periods = "2" | ||
metric_name = "MemoryUtilization" | ||
namespace = "AWS/ECS" | ||
period = "30" | ||
statistic = "Average" | ||
threshold = "75" | ||
|
||
dimensions = { | ||
ClusterName = aws_ecs_cluster.main.name | ||
ServiceName = aws_ecs_service.main[count.index].name | ||
} | ||
|
||
alarm_actions = [aws_appautoscaling_policy.up[count.index].arn] | ||
|
||
tags = var.common_tags | ||
} | ||
|
||
# CloudWatch alarm that triggers the autoscaling down policy | ||
resource "aws_cloudwatch_metric_alarm" "service_memory_low" { | ||
count = local.create_ecs_service | ||
alarm_name = "ecs_memory_utilization_low_cdq" | ||
comparison_operator = "LessThanOrEqualToThreshold" | ||
evaluation_periods = "2" | ||
metric_name = "MemoryUtilization" | ||
namespace = "AWS/ECS" | ||
period = "30" | ||
statistic = "Average" | ||
threshold = "10" | ||
|
||
dimensions = { | ||
ClusterName = aws_ecs_cluster.main.name | ||
ServiceName = aws_ecs_service.main[count.index].name | ||
} | ||
|
||
alarm_actions = [aws_appautoscaling_policy.down[count.index].arn] | ||
|
||
tags = var.common_tags | ||
} |