Skip to content

Commit

Permalink
add autoscaling to the ecs services
Browse files Browse the repository at this point in the history
  • Loading branch information
alismx committed Oct 17, 2024
1 parent 27d72e8 commit cadbd71
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions terraform/modules/ecs/ecs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,46 @@ resource "aws_ecs_service" "this" {
}
}
}

lifecycle {
ignore_changes = [desired_count]
}

tags = local.tags
}


resource "aws_appautoscaling_target" "this" {
for_each = aws_ecs_service.this
max_capacity = local.service_data[each.key].max_capacity
min_capacity = local.service_data[each.key].min_capacity
resource_id = each.value.id
scalable_dimension = "ecs:service:DesiredCount"
service_namespace = "ecs"
}

resource "aws_appautoscaling_policy" "ecs_policy" {
for_each = aws_appautoscaling_target.this
name = "${local.service_data[each.key].short_name}-scaling"
policy_type = "StepScaling"
resource_id = each.value.resource_id
scalable_dimension = each.value.scalable_dimension
service_namespace = each.value.service_namespace

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

step_adjustment {
metric_interval_lower_bound = 1.0
metric_interval_upper_bound = 2.0
scaling_adjustment = -1
}
step_adjustment {
metric_interval_lower_bound = 2.0
metric_interval_upper_bound = 3.0
scaling_adjustment = 1
}
}
}

0 comments on commit cadbd71

Please sign in to comment.