title: Terraform syntax help to include instance ids from two instances to a single array
body: <p>This is how my code looks,</p>
  <pre><code>module &quot;alb_api&quot; {
    source = &quot;./modules/load-balancer&quot;
    env = &quot;${lower(var.env)}&quot;
    project = &quot;api&quot;
    vpc_id = &quot;${data.aws_vpc.main.id}&quot;
    public_subnet1_id = &quot;${var.public_subnet1_id}&quot;
    public_subnet2_id = &quot;${var.public_subnet2_id}&quot;
    health_check_target_group_path = &quot;/status&quot;
    certificate_arn = &quot;${var.certificate_arn}&quot;
    alb_target_group_port = &quot;1984&quot;
    current_ec2_instance_ids = &quot;${aws_instance.ec2[*].id}&quot;
    next_ec2_instance_ids = &quot;${aws_instance.next_ec2[*].id}&quot;
  }
  </code></pre>
  <p>I need to be able to combine instances Ids from two instances to a single array</p>
  <p><strong>Expectation</strong></p>
  <pre><code>ec2_instance_ids = &quot;${aws_instance.ec2[*].id},${aws_instance.next_ec2[*].id}&quot;
  </code></pre>
  <p>This give me a syntax error, Is it possible to achieve this ? what would be the proper syntax is so ?</p>
  <p>Inside the module I'm registering these instances to a load-balancer, code below</p>
  <pre><code>resource &quot;aws_alb_target_group_attachment&quot; &quot;alb_target_group_attachment&quot; {
    count = length(&quot;${var.current_ec2_instance_ids}&quot;)
    target_group_arn = &quot;${aws_alb_target_group.alb_target_group.arn}&quot;
    target_id = &quot;${var.current_ec2_instance_ids[count.index]}&quot;
    port = &quot;${var.alb_target_group_port}&quot;
  }
  
  resource &quot;aws_alb_target_group_attachment&quot; &quot;next_alb_target_group_attachment&quot; {
    count = length(&quot;${var.next_ec2_instance_ids}&quot;)
    target_group_arn = &quot;${aws_alb_target_group.alb_target_group.arn}&quot;
    target_id = &quot;${var.next_ec2_instance_ids[count.index]}&quot;
    port = &quot;${var.alb_target_group_port}&quot;
  }
  </code></pre>
  <p>I need to combine these to a single as well</p>
  <pre><code>resource &quot;aws_alb_target_group_attachment&quot; &quot;alb_target_group_attachment&quot; {
    count = length(&quot;${var.ec2_instance_ids}&quot;)
    target_group_arn = &quot;${aws_alb_target_group.alb_target_group.arn}&quot;
    target_id = &quot;${var.ec2_instance_ids[count.index]}&quot;
    port = &quot;${var.alb_target_group_port}&quot;
  }
  </code></pre>
  <p><strong>Current version of code</strong></p>
  <pre><code>module &quot;alb_example-backend&quot; {
    source = &quot;./modules/load-balancer&quot;
    env = &quot;${lower(var.env)}&quot;
    project = &quot;example-backend&quot;
    vpc_id = &quot;${data.aws_vpc.main.id}&quot;
    public_subnet1_id = &quot;${var.public_subnet1_id}&quot;
    public_subnet2_id = &quot;${var.public_subnet2_id}&quot;
    health_check_target_group_path =&quot;/status&quot;
    certificate_arn = &quot;${var.certificate_arn}&quot;
    alb_target_group_port = &quot;2010&quot;
    ec2_instance_ids = concat(aws_instance.ec2[*].id,aws_instance.next_ec2[*].id)
  }
  </code></pre>
  <pre><code>resource &quot;aws_alb_target_group_attachment&quot; &quot;alb_target_group_attachment&quot; {
    count = length(&quot;${var.ec2_instance_ids}&quot;)
    target_group_arn = &quot;${aws_alb_target_group.alb_target_group.arn}&quot;
    target_id = &quot;${var.ec2_instance_ids[count.index]}&quot;
    port = &quot;${var.alb_target_group_port}&quot;
  }
  </code></pre>