不能在目标组目标类型 = 'alb' 时对任务定义使用任何network_mode值



这是我的目标群体:

resource "aws_lb_target_group" "hello-world-nginx-target-group" {
name = "hello-world-nginx"
target_type = "alb"
port = 80
protocol = "TCP"
vpc_id = "vpc-0xxxxxxxxxxxxxxb"
}

这是我的服务:

resource "aws_ecs_service" "hello-world-nginx-service" {
name = "hello-world-nginx"
cluster = "ste-test"
task_definition = aws_ecs_task_definition.hello-world-nginx-task-definition.arn
desired_count = 1
launch_type = "EC2"
ordered_placement_strategy {
type = "binpack"
field = "cpu"
}
load_balancer {
target_group_arn = aws_lb_target_group.hello-world-nginx-target-group.arn
container_name = "hello-world-nginx"
container_port = 80
}
placement_constraints {
type = "memberOf"
expression = "attribute:ecs.availability-zone in [eu-west-2a]"
}
}

这是我的任务定义:

resource "aws_ecs_task_definition" "hello-world-nginx-task-definition" {
family = "service"
network_mode = "bridge"
container_definitions = jsonencode([
{
name = "hello-world-nginx"
image = "hello-world-nginx:latest"
cpu = 10
memory = 512
essential = true
portMappings = [
{
containerPort = 80
hostPort = 80
}
]
}
])
volume {
name = "service-storage"
host_path = "/ecs/service-storage"
}
placement_constraints {
type = "memberOf"
expression = "attribute:ecs.availability-zone in [eu-west-2a]"
}
}

对于任务定义network_mode值,我已经尝试(用于测试)host,bridgeawsvpc,它们都返回以下错误:

The provided target group arn:aws:elasticloadbalancing:xxxxxxx:targetgroup/hello-world-nginx/xxxxxxxxx has target type alb, which is incompatible with the bridge (or host or awsvpc) network mode specified in the task definition.

目标类型应该是"ip""instance"在您的目标组和协议http,因为您使用的是ALB,而不是NLB

resource "aws_lb_target_group" "hello-world-nginx-target-group" {
name = "hello-world-nginx"
target_type = "instance"
port = 80
protocol = "HTTP"
vpc_id = "vpc-0xxxxxxxxxxxxxxb"
}

相关内容

最新更新