【发布时间】:2021-05-08 12:40:18
【问题描述】:
我正在使用 Terraform 部署我的基础架构,但一直遇到以下错误:
Error: InvalidParameterException: The target group with targetGroupArn [snip] does
not have an associated load balancer.
有another question here on SO where the poster is running into a similar problem。答案之一引用了 AWS 文档:
Amazon ECS 服务需要显式依赖 Application Load Balancer 侦听器规则和 Application Load 平衡器监听器。这可以防止服务在 监听器已准备就绪。
这基本上是说我应该在我的服务之前创建我的监听器和监听器规则。但是,在我的侦听器中,我将服务的目标组指定为默认操作:
resource "aws_alb_listener" "app_http" {
load_balancer_arn = module.alb_app.arn
port = 80
protocol = "HTTP"
default_action {
target_group_arn = module.app_service.lb_target_group.id
type = "forward"
}
}
所以,如果应该在我的服务和目标组之前创建侦听器,我对如何在侦听器上设置 target_group_arn 感到困惑。
这就是我创建服务及其相应目标组的方式:
resource "aws_ecs_service" "service" {
...
load_balancer {
target_group_arn = aws_alb_target_group.service.arn
}
}
resource "aws_alb_target_group" "service" {
...
port = 8080
protocol = "HTTP"
vpc_id = var.vpc_id
target_type = "ip"
}
【问题讨论】:
-
为什么要在模块外创建目标组?您是否尝试在模块中移动它?另外,检查
module.app_service.lb_target_group.id是否真的给了你 arn 而不是别的东西
标签: amazon-web-services terraform amazon-ecs terraform-provider-aws aws-load-balancer