title: Terraform Module Call with for_each and ARN List Output
body: <p>I am calling a root module via child module as follows:</p>
  <p><strong>child module - main.tf</strong></p>
  <pre><code>  module &quot;create_network_lb&quot; {
    source             = &quot;../../modules/lb_test&quot;
    for_each           = var.target_groups
    
    name                   = each.key
    tg_name                = each.value.tg_name
    tg_backend_port        = each.value.tg_backend_port
    tg_backend_protocol    = each.value.tg_backend_protocol
    tg_hc_port             = each.value.tg_hc_port
    tg_hc_protocol         = each.value.tg_hc_protocol
    tg_htl_port            = each.value.tg_htl_port
    tg_htl_protocol        = each.value.tg_htl_protocol
    tg_htl_action          = lookup(each.value, &quot;tg_htl_action&quot;, &quot;forward&quot;)
    subnets                = tolist(data.aws_subnet_ids.private_compute[0].ids)
    vpc_id                 = sort(data.aws_vpcs.platform_private_vpc.ids)[0]
  }
  </code></pre>
  <p><strong>child module - vars.tf</strong></p>
  <pre><code>variable &quot;target_groups&quot; {
    description = &quot;A list of maps containing key/value pairs that define the target groups to be created. Order of these maps is important and the index of these are to be referenced in listener definitions. Required key/values: name, backend_protocol, backend_port&quot;
    type        = map
    default     = {
      lb-1 = {
        tg_name = &quot;test1&quot;
        tg_backend_protocol = &quot;TCP&quot;
        tg_backend_port = &quot;80&quot;
        tg_target_type = &quot;instance&quot;
        tg_deregistration_delay = &quot;180&quot;
        tg_hc_healthy_threshold = 3
        tg_hc_interval = 30
        tg_hc_port = 80
        tg_hc_protocol = &quot;TCP&quot;
        tg_hc_unhealthy_threshold = 3
        tg_htl_port = &quot;80&quot;
        tg_htl_protocol = &quot;TCP&quot;
      }
      lb-2 = {
        tg_name = &quot;test2&quot;
        tg_backend_protocol = &quot;TCP&quot;
        tg_backend_port = &quot;8080&quot;
        tg_target_type = &quot;instance&quot;
        tg_deregistration_delay = &quot;180&quot;
        tg_hc_healthy_threshold = 3
        tg_hc_interval = 30
        tg_hc_port = 8080
        tg_hc_protocol = &quot;TCP&quot;
        tg_hc_unhealthy_threshold = 3
        tg_htl_port = &quot;80&quot;
        tg_htl_protocol = &quot;TCP&quot;
      }
    }
  }
  </code></pre>
  <p><strong>root module - main.tf</strong></p>
  <pre><code>resource &quot;aws_lb_target_group&quot; &quot;main&quot; {
    name                               = var.tg_name
    vpc_id                             = var.vpc_id
    port                               = var.tg_backend_port
    protocol                           = var.tg_backend_protocol
    depends_on = [aws_lb.default]
  
    lifecycle {
      create_before_destroy = true
    }
  }
  
  resource &quot;aws_lb_listener&quot; &quot;frontend_http_tcp&quot; {
    load_balancer_arn = aws_lb.default.arn
    port              = var.tg_htl_port
    protocol          = var.tg_htl_protocol
    
    default_action {
      type = var.tg_htl_action
      target_group_arn = aws_lb_target_group.main.arn
    }
  
  }
  </code></pre>
  <p><strong>root module - outputs.tf</strong></p>
  <pre><code>output &quot;target_group_arns&quot; {
    description = &quot;ARNs of the target groups. Useful for passing to your Auto Scaling group.&quot;
    value       = aws_lb_target_group.main.arn
  }
  </code></pre>
  <p>Inside the child module, an additional module is called to create an Auto Scaling Group</p>
  <pre><code>module &quot;create_autoscaling_group&quot; {
    source                    = &quot;../../modules/cloudformation_stack_autoscaling&quot;
    template_name             = &quot;launch-template&quot;
    cf_stack_name             = &quot;stack&quot;
    autoscaling_group_name    = &quot;asg&quot;
    instance_type             = var.vm_type
    block_device_mappings     = var.block_device_mappings
    image_id                  = data.aws_ami.centos_ami.image_id
    vpc_security_group_ids    = concat(data.aws_security_groups.security_group_ids.ids, [module.create_security_group.id])
    user_data_base64          = data.template_cloudinit_config.config.rendered
    iam_instance_profile_name = var.iam_instance_profile_name
    volume_tags               = merge(local.vmss_tags,{&quot;fds:cloudformation:stack-name&quot;=local.stack_tag})
    ec2_tags                  = var.vmss_tags
    subnet_ids                = tolist(data.aws_subnet_ids.private_compute[0].ids)
    max_size                  = var.vm_count != 0 ? var.vm_count : var.max_size
    min_size                  = var.vm_count != 0 ? var.vm_count : var.min_size
    desired_capacity          = var.vm_count != 0 ? var.vm_count : var.desired_capacity
    health_check_type         = var.health_check_type
    health_check_grace_period = var.health_check_grace_period
    target_group_arns         = module.create_network_lb[*].target_group_arns
   
  </code></pre>
  <p>Notice the variable, 'target_group_arns'. Here I need the arn of all target groups created by the call to the 'create_network_lb' module, so that all LBs and its associated targets groups are managed by the 1 Auto Scaling Group.</p>
  <p>From what I read, when using a for_each, as I did with the 'create_network_lb' module call, I cannot use splat expressions. I tried using list comprehension but must be doing it wrong. Any help here would be appreciated.</p>