Help associating ASG with ALB target group using modules

Hello Terraform community,

I’m reaching out for help after struggling with an issue for several days. I’m likely confusing something or missing a key detail.

I’m currently using two AWS modules:

  • terraform-aws-modules/autoscaling/aws
  • terraform-aws-modules/alb/aws

Everything works well so far. However, when I try to associate my Auto Scaling Group (ASG) with a target group from the ALB module, I run into an error.

The ALB module documentation doesn’t seem to provide a clear example for this use case. I attempted to use the following approach based on the resource documentation:

target_group_arns = [module.alb.target_groups[“asg_group”].arn]

But it doesn’t work — I keep getting errors.

Has anyone faced a similar issue? How can I correctly associate my ASG with the ALB target group when using these modules?

Thanks in advance!

"Here is the full code if you’re interested in checking it out: https://github.com/salahbouabid7/MEmo"