ALB register container instances supported?
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?
yes it does.
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 ?
I came across the same question, the only answer was pretty much this ticket
@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
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
}
}