Skip to content

Commit

Permalink
Merge pull request #3403 from ministryofjustice/LAWS-3476-ecs-scaling-3
Browse files Browse the repository at this point in the history
Laws 3476 ecs scaling 3
  • Loading branch information
vc13837 authored Sep 19, 2023
2 parents 75cd9d3 + 26bd729 commit 3fb052a
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 63 deletions.
8 changes: 4 additions & 4 deletions terraform/environments/mlra/application_variables.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@
"maat_api_end_point": "http://maat-cd-api.aws.prd.legalservices.gov.uk/maatApi/laaStatus",
"maat_db_url": "rds.maat.aws.prd.legalservices.gov.uk:1521:MAATDB",
"maat_libra_wsdl_url": "http://infox.aws.prd.legalservices.gov.uk/infoX/gateway",
"ec2_desired_capacity": 0,
"ec2_desired_capacity": 2,
"ec2_max_size": 6,
"ec2_min_size": 0,
"ec2_min_size": 2,
"task_definition_volume": "upload_volume",
"network_mode": "bridge",
"server_port": 8080,
"app_count": 0,
"appscaling_min_capacity": 0,
"app_count": 2,
"appscaling_min_capacity": 2,
"appscaling_max_capacity": 6,
"ec2_scaling_cpu_threshold": 75,
"ec2_scaling_mem_threshold": 61,
Expand Down
118 changes: 59 additions & 59 deletions terraform/environments/mlra/modules/ecs/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ resource "aws_autoscaling_group" "cluster-scaling-group" {
desired_capacity = var.ec2_desired_capacity
max_size = var.ec2_max_size
min_size = var.ec2_min_size
# protect_from_scale_in = true
protect_from_scale_in = true

launch_template {
id = aws_launch_template.ec2-launch-template.id
Expand All @@ -38,11 +38,11 @@ resource "aws_autoscaling_group" "cluster-scaling-group" {
propagate_at_launch = true
}

# tag {
# key = "AmazonECSManaged"
# value = true
# propagate_at_launch = true
# }
tag {
key = "AmazonECSManaged"
value = true
propagate_at_launch = true
}

dynamic "tag" {
for_each = var.tags_common
Expand Down Expand Up @@ -270,38 +270,38 @@ resource "aws_iam_role_policy_attachment" "attach_ec2_policy" {

# EC2 Target Tracking scaling

resource "aws_autoscaling_policy" "ec2-cpu-scaling-target" {
name = "ec2-cpu-scaling-target"
policy_type = "TargetTrackingScaling"
autoscaling_group_name = aws_autoscaling_group.cluster-scaling-group.name
estimated_instance_warmup = 200
target_tracking_configuration {
predefined_metric_specification {
predefined_metric_type = "ASGAverageCPUUtilization"
}
target_value = var.ec2_scaling_cpu_threshold
}
}
# resource "aws_autoscaling_policy" "ec2-cpu-scaling-target" {
# name = "ec2-cpu-scaling-target"
# policy_type = "TargetTrackingScaling"
# autoscaling_group_name = aws_autoscaling_group.cluster-scaling-group.name
# estimated_instance_warmup = 200
# target_tracking_configuration {
# predefined_metric_specification {
# predefined_metric_type = "ASGAverageCPUUtilization"
# }
# target_value = var.ec2_scaling_cpu_threshold
# }
# }

resource "aws_autoscaling_policy" "ec2-mem-scaling-target" {
name = "ec2-mem-scaling-target"
policy_type = "TargetTrackingScaling"
autoscaling_group_name = aws_autoscaling_group.cluster-scaling-group.name
estimated_instance_warmup = 200
target_tracking_configuration {
target_value = var.ec2_scaling_mem_threshold
disable_scale_in = false
customized_metric_specification {
metric_name = "mem_used_percent"
namespace = "CWAgent"
statistic = "Average"
metric_dimension {
name = "InstanceId"
value = "${var.app_name}-cluster-scaling-group"
}
}
}
}
# resource "aws_autoscaling_policy" "ec2-mem-scaling-target" {
# name = "ec2-mem-scaling-target"
# policy_type = "TargetTrackingScaling"
# autoscaling_group_name = aws_autoscaling_group.cluster-scaling-group.name
# estimated_instance_warmup = 200
# target_tracking_configuration {
# target_value = var.ec2_scaling_mem_threshold
# disable_scale_in = false
# customized_metric_specification {
# metric_name = "mem_used_percent"
# namespace = "CWAgent"
# statistic = "Average"
# metric_dimension {
# name = "InstanceId"
# value = "${var.app_name}-cluster-scaling-group"
# }
# }
# }
# }



Expand Down Expand Up @@ -373,12 +373,12 @@ resource "aws_ecs_service" "ecs_service" {
cluster = aws_ecs_cluster.ecs_cluster.id
task_definition = data.aws_ecs_task_definition.task_definition.id
desired_count = var.app_count
launch_type = "EC2"
# launch_type = "EC2"

# capacity_provider_strategy {
# capacity_provider = aws_ecs_capacity_provider.mlra.name
# weight = 1
# }
capacity_provider_strategy {
capacity_provider = aws_ecs_capacity_provider.mlra.name
weight = 1
}

health_check_grace_period_seconds = 300

Expand Down Expand Up @@ -572,25 +572,25 @@ resource "aws_appautoscaling_policy" "ecs_target_memory" {
}
}

# resource "aws_ecs_capacity_provider" "mlra" {
# name = "${var.app_name}-${var.environment}-capacity-provider"
resource "aws_ecs_capacity_provider" "mlra" {
name = "${var.app_name}-${var.environment}-capacity-provider"

# auto_scaling_group_provider {
# auto_scaling_group_arn = aws_autoscaling_group.cluster-scaling-group.arn
# managed_termination_protection = "ENABLED"
auto_scaling_group_provider {
auto_scaling_group_arn = aws_autoscaling_group.cluster-scaling-group.arn
managed_termination_protection = "ENABLED"

# managed_scaling {
# # maximum_scaling_step_size = 1000
# # minimum_scaling_step_size = 1
# status = "ENABLED"
# target_capacity = var.ecs_target_capacity
# }
# }
# }
managed_scaling {
# maximum_scaling_step_size = 1000
# minimum_scaling_step_size = 1
status = "ENABLED"
target_capacity = var.ecs_target_capacity
}
}
}

# resource "aws_ecs_cluster_capacity_providers" "mlra" {
# cluster_name = aws_ecs_cluster.ecs_cluster.name
resource "aws_ecs_cluster_capacity_providers" "mlra" {
cluster_name = aws_ecs_cluster.ecs_cluster.name

# capacity_providers = [aws_ecs_capacity_provider.mlra.name]
# }
capacity_providers = [aws_ecs_capacity_provider.mlra.name]
}

0 comments on commit 3fb052a

Please sign in to comment.