Terraform aws-lb-target-group problems

Hi there,

My situation is as follows:
I’m creating a AWS ECS (NGINX container for SFTP traffic) FARGATE setup with Terraform with a network load balancer infront of it. I’ve got most parts set-up just fine and the current setup works. But now i want to add more target groups to the setup so i can allow more different ports to the container. My variable part is as follows:

variable “sftp_ports” {
type = map
default = {
test1 = {
port = 50003
}
test2 = {
port = 50004
}
}
}

and the actual deployment is as follows:

resource “aws_alb_target_group” “test” {
for_each = var.sftp_ports

name = “sftp-target-group-${each.key}”
port = each.value.port
protocol = “TCP”
target_type = “ip”
vpc_id = data.aws_vpc.default.id

depends_on = [
aws_lb.proxypoc
]
}

resource “aws_alb_listener” “ecs-alb-https-listenertest” {
for_each = var.sftp_ports
load_balancer_arn = aws_lb.proxypoc.id
port = each.value.port
protocol = “TCP”

default_action {
type = “forward”
target_group_arn = aws_alb_target_group.default-target-group.arn
}
}

This deploys the needed listeners and the target groups just fine but the only problem i have is on how i can configure the registered target part. The aws ecs service resource only allows one target group arn so i have no clue on how i can add the additional target groups in order to reach my goal. So is it possible to configure the ecs service to contain more target groups arns or am i supposed to configure only single target group with multiple ports (couldn’t do this in Terraform but it is possible if i do it manually in the GUI)?

I’d like to hear from you guys,
Thanks!