【发布时间】:2020-04-22 01:05:12
【问题描述】:
我是 Terraform 和 ECS 的新手,我正在使用 this example 创建一个 ECS EC2 类型的集群,该集群将自动扩展并使用应用程序负载均衡器。
我的问题是:main.tf 中的这段代码如何 sn-p
resource "aws_ecs_service" "test" {
name = "tf-example-ecs-ghost"
cluster = "${aws_ecs_cluster.main.id}"
task_definition = "${aws_ecs_task_definition.ghost.arn}"
desired_count = "${var.service_desired}"
iam_role = "${aws_iam_role.ecs_service.name}"
load_balancer {
target_group_arn = "${aws_alb_target_group.test.id}"
container_name = "ghost"
container_port = "2368"
}
depends_on = [
"aws_iam_role_policy.ecs_service",
"aws_alb_listener.front_end",
]
}
连接到资源aws_autoscaling_group.app:
resource "aws_autoscaling_group" "app" {
name = "tf-test-asg"
vpc_zone_identifier = ["${aws_subnet.main.*.id}"]
min_size = "${var.asg_min}"
max_size = "${var.asg_max}"
desired_capacity = "${var.asg_desired}"
launch_configuration = "${aws_launch_configuration.app.name}"
}
由于aws_ecs_service 资源定义中没有指向aws_autoscaling_group 资源的插值变量,ECS 服务定义如何知道在哪里可以找到此自动缩放组?它引用了一个目标组,但目标组不引用自动缩放组。这就是为什么我很困惑,因为资源“ecs-service”和资源“aws-autoscaling”之间没有明显的参考。或者代码可能丢失了?请尽可能提供详尽的解释。
【问题讨论】:
标签: amazon-web-services terraform amazon-ecs autoscaling