title: Iterating through a list of resource values inside a list in a Terraform local
body: <p>I am trying to get an array of arrays to use in a Terraform template_file data field:</p>
  
  <pre><code>data "template_file" "dashboard" {
    template = "${file("${path.module}/files/dashboard.json")}"
  
    vars {
      metrics = "${jsonencode(local.metrics)}"
    }
  }
  </code></pre>
  
  <p>But I am not finding the proper way to get what I want. I have an aws_instance resource with a count of 3, and I am trying to generate 3 arrays inside a local based on each one of the resource counts. The only thing I've come up with so far is:</p>
  
  <pre><code>locals {
    metrics = [
      "collectd", "GenericJMX.gauge.50thPercentile", "Host", "${aws_instance.instance.*.id}", "PluginInstance", "cassandra_client_request-latency"
    ]
  }
  </code></pre>
  
  <p>Obviously what this does, is put all the instances one after the other in the same array. What I am trying to achieve is a result array that would look like:</p>
  
  <pre><code>["collectd", "GenericJMX.gauge.50thPercentile", "Host", "the id of instance 0", PluginInstance", "cassandra_client_request-latency"], 
  ["collectd", "GenericJMX.gauge.50thPercentile", "Host", "the id of instance 1", PluginInstance", "cassandra_client_request-latency"], 
  ["collectd", "GenericJMX.gauge.50thPercentile", "Host", "the id of instance 3", PluginInstance", "cassandra_client_request-latency"]
  </code></pre>
  
  <p>And this would be  expanded in the template ${metrics} variable.</p>
  
  <p>Is there any way to achieve what I want, inside a local, and make it usable in the template?</p>