title: Terraform setproduct function with more than two lists
body: <p>How to use terraform setproduct function with more than 2 lists in the below scenario or is there any other way to achieve the end result.</p>
  <p>In main.tf file I have the following data.</p>
  <pre><code>$ cat main.tf
  variable &quot;nodes&quot; {
    default = [&quot;1&quot;, &quot;2&quot;, &quot;3&quot;]
  }
  
  variable &quot;ebs_volumes&quot; {
    default = [
      {
        ebs_name = &quot;/dev/xdba&quot;
        ebs_size = &quot;50&quot;
        ebs_type = &quot;gp2&quot;
      },
      {
        ebs_name = &quot;/dev/xdbb&quot;
        ebs_size = &quot;20&quot;
        ebs_type = &quot;gp2&quot;
      }
    ]
  }
  
  locals {
    ebs_name = [for i in var.ebs_volumes : i.ebs_name]
    ebs_size = [for i in var.ebs_volumes : i.ebs_size]
    ebs_type = [for i in var.ebs_volumes : i.ebs_type]
  }
  
  locals {
    node_disks = { for pair in setproduct(var.nodes, local.ebs_name) : &quot;${pair[0]}:${pair[1]}&quot; =&gt; {
      node_index = pair[0]
      ebs_name   = pair[1]
      ebs_size   = [for i in var.ebs_volumes : i.ebs_size]
      ebs_type   = [for i in var.ebs_volumes : i.ebs_type]
    } }
  }
  
  output &quot;combined&quot; {
    value = local.node_disks
  }
  </code></pre>
  <p>When I run terraform apply I get the following result</p>
  <pre><code>    $ terraform apply
  
  Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
  
  Outputs:
  
  combined = {
    &quot;1:/dev/xdba&quot; = {
      &quot;ebs_name&quot; = &quot;/dev/xdba&quot;
      &quot;ebs_size&quot; = [
        &quot;50&quot;,
        &quot;20&quot;,
      ]
      &quot;ebs_type&quot; = [
        &quot;gp2&quot;,
        &quot;gp2&quot;,
      ]
      &quot;node_index&quot; = &quot;1&quot;
    }
    &quot;1:/dev/xdbb&quot; = {
      &quot;ebs_name&quot; = &quot;/dev/xdbb&quot;
      &quot;ebs_size&quot; = [
        &quot;50&quot;,
        &quot;20&quot;,
      ]
      &quot;ebs_type&quot; = [
        &quot;gp2&quot;,
        &quot;gp2&quot;,
      ]
      &quot;node_index&quot; = &quot;1&quot;
    }
    &quot;2:/dev/xdba&quot; = {
      &quot;ebs_name&quot; = &quot;/dev/xdba&quot;
      &quot;ebs_size&quot; = [
        &quot;50&quot;,
        &quot;20&quot;,
      ]
      &quot;ebs_type&quot; = [
        &quot;gp2&quot;,
        &quot;gp2&quot;,
      ]
      &quot;node_index&quot; = &quot;2&quot;
    }
    &quot;2:/dev/xdbb&quot; = {
      &quot;ebs_name&quot; = &quot;/dev/xdbb&quot;
      &quot;ebs_size&quot; = [
        &quot;50&quot;,
        &quot;20&quot;,
      ]
      &quot;ebs_type&quot; = [
        &quot;gp2&quot;,
        &quot;gp2&quot;,
      ]
      &quot;node_index&quot; = &quot;2&quot;
    }
    &quot;3:/dev/xdba&quot; = {
      &quot;ebs_name&quot; = &quot;/dev/xdba&quot;
      &quot;ebs_size&quot; = [
        &quot;50&quot;,
        &quot;20&quot;,
      ]
      &quot;ebs_type&quot; = [
        &quot;gp2&quot;,
        &quot;gp2&quot;,
      ]
      &quot;node_index&quot; = &quot;3&quot;
    }
    &quot;3:/dev/xdbb&quot; = {
      &quot;ebs_name&quot; = &quot;/dev/xdbb&quot;
      &quot;ebs_size&quot; = [
        &quot;50&quot;,
        &quot;20&quot;,
      ]
      &quot;ebs_type&quot; = [
        &quot;gp2&quot;,
        &quot;gp2&quot;,
      ]
      &quot;node_index&quot; = &quot;3&quot;
    }
  }
  </code></pre>
  <p>Instead I want to be able to have the result as shown below (psudo code):</p>
  <pre><code>combined = {
    &quot;1:/dev/xvdb&quot; = {
      &quot;disk_dev_path&quot; = &quot;/dev/xvda&quot;
      &quot;node_name&quot; = &quot;1&quot;
      &quot;disk_size&quot; = &quot;10&quot;
      &quot;disk_type&quot; = &quot;gp2&quot;
    }
    &quot;1:/dev/xvdc&quot; = {
      &quot;disk_dev_path&quot; = &quot;/dev/xvdb&quot;
      &quot;node_name&quot; = &quot;1&quot;
      &quot;disk_size&quot; = &quot;30&quot;
      &quot;disk_type&quot; = &quot;gp2&quot;
    }
    &quot;2:/dev/xvdb&quot; = {
      &quot;disk_dev_path&quot; = &quot;/dev/xvda&quot;
      &quot;node_name&quot; = &quot;2&quot;
      &quot;disk_size&quot; = &quot;10&quot;
      &quot;disk_type&quot; = &quot;gp2&quot;
    }
    &quot;2:/dev/xvdc&quot; = {
      &quot;disk_dev_path&quot; = &quot;/dev/xvdb&quot;
      &quot;node_name&quot; = &quot;2&quot;
      &quot;disk_size&quot; = &quot;30&quot;
      &quot;disk_type&quot; = &quot;gp2&quot;
    }
    &quot;3:/dev/xvdb&quot; = {
      &quot;disk_dev_path&quot; = &quot;/dev/xvda&quot;
      &quot;node_name&quot; = &quot;3&quot;
      &quot;disk_size&quot; = &quot;10&quot;
      &quot;disk_type&quot; = &quot;gp2&quot;
    }
    &quot;3:/dev/xvdc&quot; = {
      &quot;disk_dev_path&quot; = &quot;/dev/xvdb&quot;
      &quot;node_name&quot; = &quot;3&quot;
      &quot;disk_size&quot; = &quot;30&quot;
      &quot;disk_type&quot; = &quot;gp2&quot;
    }
  }
  </code></pre>
  <p>How to achieve this?</p>
  <p>I need this in order to use this in <strong>for_each</strong> to create ec2 instances and ebs volumes and attach them respectively whenever user adds an input in the variable using our ec2 module.</p>