terraform-aws-ecs-web-app icon indicating copy to clipboard operation
terraform-aws-ecs-web-app copied to clipboard

ALB register container instances supported?

Open archenroot opened this issue 6 years ago • 5 comments

Hi,

I don't see any aws_lb_target_group_attachment resource being used, but it can be hidden somewhere in submodules being used.

Does this module cover registering container instances in ALB target group?

archenroot avatar Nov 14 '19 14:11 archenroot

yes it does.

jamengual avatar Jul 09 '20 18:07 jamengual

The alb_ingress module is used in this module which creates aws_lb_target_group and aws_lb_listener_rule resources. https://github.com/cloudposse/terraform-aws-alb-ingress/blob/master/main.tf

The aws_lb_target_group is passed into the ecs_alb_service_task module using the dictionary var.ecs_load_balancers which then connects the aws_ecs_service to the target group.

https://github.com/cloudposse/terraform-aws-ecs-alb-service-task/blob/master/main.tf#L308

But I don't see a aws_lb_target_group_attachment. Do you @jamengual ?

nitrocode avatar Jul 10 '20 11:07 nitrocode

I came across the same question, the only answer was pretty much this ticket

BGarber42 avatar Jul 29 '21 08:07 BGarber42

@BGarber42 @archenroot Oh I was mistaken. You do not need a target group attachment. I believe only the listener rule (created by the alb_ingress module) is required as that attaches the target group to the ALB's listener arn.

https://github.com/cloudposse/terraform-aws-alb-ingress/blob/ab6033cc736fa37fc4e65ab897423a438b45e6f5/main.tf#L49-L58

nitrocode avatar Jul 30 '21 22:07 nitrocode

I just ran into this again. I'm glad this ticket was written because the above description reminded me that I do not need a specific aws_lb_target_group_attachment.

If you want to create an attachment outside of this module, the following can be done.

module "ecs_web_app" {
  # ...
}

resource "aws_lb_target_group_attachment" "default" {
  target_group_arn = module.ecs_web_app.alb_ingress_target_group_arn

  # Replace with your target_id
  # target_id = null
}

There are very few inputs to this and we could add this as an optional resource within this module but it's unnecessary if you rely on listener rules to direct directly to the LB.

The attachment only seems necessary if the listener rule directs directly to the target group

resource "aws_lb_listener" "default" {
  default_action {
    type             = "forward"
    target_group_arn = module.ecs_web_app.alb_ingress_target_group_arn
  }
}

nitrocode avatar Jul 01 '22 14:07 nitrocode