我正试图在AWS Fargate集群服务中使用带有自动缩放功能的Terraform来实现计划自动缩放。
我的要求是,我想在美国东部时间早上7点扩展我的ECS服务,并在美国中部时间晚上7点扩展。对于扩展ECS服务,我在Terraform中使用计划扩展,它运行良好。但我在这里关心的是如何使用相同或不同的逻辑进行扩展。在这里,我尝试使用不同的逻辑进行放大和缩小。当我在应用terraform apply
时同时使用两个逻辑时,它的给出错误类似
Error: ConcurrentUpdateException: You already have a pending update to an Auto Scaling resource.
我在特定的时间使用下面的代码成功地自动扩展了我的ECS服务。现在我可以在特定的时间扩展我的ECS服务吗?
resource "aws_appautoscaling_target" "my_service" {
max_capacity = var.my_service-max_count
min_capacity = var.my_service-count
resource_id = "service/mycluster/${aws_ecs_service.my_service.name}"
scalable_dimension = "ecs:service:DesiredCount"
service_namespace = "ecs"
}
resource "aws_appautoscaling_scheduled_action" "my_service" {
name = "my_service"
service_namespace = "${aws_appautoscaling_target.my_service.service_namespace}"
resource_id = "${aws_appautoscaling_target.my_service.resource_id}"
scalable_dimension = "${aws_appautoscaling_target.my_service.scalable_dimension}"
schedule = "cron(0 7 * * ? *)"
scalable_target_action {
min_capacity = 2
max_capacity = 10
}
}
resource "aws_appautoscaling_scheduled_action" "my_service_scale_out" {
name = "my_service"
service_namespace = "${aws_appautoscaling_target.my_service.service_namespace}"
resource_id = "${aws_appautoscaling_target.my_service.resource_id}"
scalable_dimension = "${aws_appautoscaling_target.my_service.scalable_dimension}"
schedule = "cron(0 19 * * ? *)"
scalable_target_action {
min_capacity = 1
max_capacity = 1
}
}
我遇到了同样的问题,然后在这里找到了解决方案:https://keita.blog/2018/01/29/aws-application-auto-scaling-for-ecs-with-terraform/
只需添加:
depends_on = ["aws_appautoscaling_scheduled_action.my_service"]
在您的资源my_service_scale_out
中