title: How to extract particular indexes from within a list in terraform?
body: <p>I'm trying to extract only particular indexes from the list.</p>
  <p><strong>Module Block</strong></p>
  <pre><code>module &quot;app_sg&quot; {
    source        = &quot;../modules/sg/sg_rules&quot;
    ingress_rules = var.app_ingress_rules
    egress_rules  = var.app_egress_rules
    ingress_sg    = var.app_ingress_sg
    egress_sg     = var.app_egress_sg
    src_sg_id     = [&quot;module.app_sgs.sg_id[0]&quot;, &quot;module.app_sgs.sg_id[2]&quot;]
    sg_id         = module.app_sgs.sg_id[0]
    depends_on    = [module.app_sgs]
  }
  </code></pre>
  <p><strong>Resource Block</strong></p>
  <pre><code># Application security group rules creation
  resource &quot;aws_security_group_rule&quot; &quot;ingress_cidr&quot; {
    for_each          = var.ingress_rules != &quot;&quot; ? var.ingress_rules : {}
    type              = &quot;ingress&quot;
    from_port         = each.key
    to_port           = each.key
    protocol          = &quot;tcp&quot;
    security_group_id = var.sg_id
    cidr_blocks       = each.value
  }
  
  resource &quot;aws_security_group_rule&quot; &quot;egress_cidr&quot; {
    for_each          = var.egress_rules != &quot;&quot; ? var.egress_rules : {}
    type              = &quot;egress&quot;
    from_port         = each.key
    to_port           = each.key
    protocol          = &quot;tcp&quot;
    security_group_id = var.sg_id
    cidr_blocks       = each.value
  }
  
  resource &quot;aws_security_group_rule&quot; &quot;ingress_sg&quot; {
    for_each                 = var.ingress_sg != &quot;&quot; ? var.ingress_sg : {}
    type                     = &quot;ingress&quot;
    from_port                = each.key
    to_port                  = each.key
    protocol                 = &quot;tcp&quot;
    security_group_id        = var.sg_id
    source_security_group_id = var.src_sg_id
  }
  
  resource &quot;aws_security_group_rule&quot; &quot;egress_sg&quot; {
    for_each                 = var.egress_sg != &quot;&quot; ? var.egress_sg : {}
    type                     = &quot;egress&quot;
    from_port                = each.key
    to_port                  = each.key
    protocol                 = &quot;tcp&quot;
    security_group_id        = var.sg_id
    source_security_group_id = var.src_sg_id
  }
  </code></pre>
  <p>While running <code>terraform apply</code> it throws an error like below</p>
  <pre><code>Error: Incorrect attribute value type
  
    on ../modules/sg/sg_rules/main.tf line 29, in resource &quot;aws_security_group_rule&quot; &quot;ingress_sg&quot;:
    29:   source_security_group_id = var.src_sg_id
      |----------------
      | var.src_sg_id is tuple with 2 elements
  
  Inappropriate value for attribute &quot;source_security_group_id&quot;: string required.
  </code></pre>
  <p>Could someone please provide me a solution for this scenario? Eventually I need to pass multiple <code>source_security_group_id</code> within the security group rule. I have tried <code>slice</code> function, but it can extract only the <code>start</code> and <code>end</code> indexes.</p>