【发布时间】:2019-05-31 15:55:12
【问题描述】:
我们有一个想要扩展 ECS 服务的用例。大约有10个服务。我不想在每个服务模块中添加缩放代码。另外,我不想为此创建一个模块并为根模块 main.tf 中的每个服务调用它们。
在下面的代码中,只有少数变量会针对示例服务名称、目标组 arn 等进行更改。
resource "aws_appautoscaling_target" "ecs_target" {
max_capacity = "${var.max_capacity}"
min_capacity = "${var.min_capacity}"
resource_id = "service/${var.cluster}/${aws_ecs_service.rc.name}"
scalable_dimension = "ecs:service:DesiredCount"
service_namespace = "ecs"
}
resource "aws_appautoscaling_policy" "ecs_policy" {
#count = "${var.auto_scaling_enabled}"
name = "rc-ecs-auto-scale"
policy_type = "TargetTrackingScaling"
resource_id = "service/cluster/${aws_ecs_service.rc.name}"
scalable_dimension = "ecs:service:DesiredCount"
service_namespace = "ecs"
target_tracking_scaling_policy_configuration {
predefined_metric_specification {
predefined_metric_type = "ALBRequestCountPerTarget"
resource_label = "${var.alb_arn_suffix}/${aws_alb_target_group.rc.arn_suffix}"
}
target_value = "${var.threshold_value_to_scale}"
scale_in_cooldown = "${var.scale_in_cooldown}"
scale_out_cooldown = "${var.scale_out_cooldown}"
}
depends_on = ["aws_appautoscaling_target.ecs_target"]
}
实现这一目标的最佳方法是什么?
【问题讨论】:
标签: terraform