title: Combine two maps to create a third map in Terraform 0.12
body: <p>I have a requirement to do some complicated merging of input data in Terraform 0.12. I can't figure out if it's possible, but maybe I'm just doing something wrong.</p>
  
  <p>I have two variables:</p>
  
  <pre class="lang-hcl prettyprint-override"><code>variable "ebs_block_device" {
    description = "Additional EBS block devices to attach to the instance"
    type        = list(map(string))
    default     = [
      {
        device_name = "/dev/sdg"
        volume_size = 5
        volume_type = "gp2"
        delete_on_termination = false
      },
      {
        device_name = "/dev/sdh"
        volume_size = 5
        volume_type = "gp2"
        delete_on_termination = false
      }
    ]
  }
  
  variable "mount_point" {
    description = "Mount point to use"
    type = list(string)
    default = ["/data", "/home"]
  }
  </code></pre>
  
  <p>I want to then combine these sources inside a template like this:</p>
  
  <pre class="lang-bash prettyprint-override"><code>#!/usr/bin/env bash
  %{for e in merged ~}
  mkfs -t xfs ${e.device_name}
  mkdir -p ${e.mount_point}
  mount ${e.device_name} ${e.mount_point}
  %{endfor}
  </code></pre>
  
  <p>Where <code>merged</code> would contain the combined data.</p>
  
  <p>It seems that only simple for loops are supported in the template language, so doing the merge in there seems to be out of the question.</p>
  
  <p>So, I assume the data munging needs to happen in the DSL. But, I would need to do this:</p>
  
  <ul>
  <li>iterate over the list of ebs_block_devices, tracking the index (like <code>enumerate()</code> in Python, or <code>each.with_index</code> in Ruby)</li>
  <li>get the corresponding element from the list of mount_points</li>
  <li>add these to a resultant map. </li>
  </ul>
  
  <p>My problem, specifically, is that there doesn't seem to be any equivalent of Python's <code>enumerate</code> function, and this prevents me tracking the index. If there was, I imagine I could do something like this:</p>
  
  <pre class="lang-hcl prettyprint-override"><code>merged = [for index, x in enumerate(var.ebs_block_device): {
    merge(x, {mount_point =&gt; var.mount_point[index]})
  }]
  </code></pre>
  
  <p>Is such a data transformation as I am trying to do here currently possible in Terraform? And if not possible, what is the preferred alternative implementation?</p>