title: Terraform assign volume to AWS instances list
body: <p>I have created a AWS instance list using Terraform:</p>
  
  <pre><code>resource "aws_instance" "masters" {
      count = 2
      ami = "${var.aws_centos_ami}"
      instance_type = "t2.micro"
      availability_zone = "eu-west-1b"
  
      tags {
              Name = "master-${count.index}"
          }
  }
  </code></pre>
  
  <p>How can I assign volumes to that instances like in a loop?
  I just trying using the next: </p>
  
  <pre><code>data "aws_ebs_volume" "masters_ebs_volume" {
      most_recent = true
      filter {
        name   = "attachment.instance-id"
        values = ["${aws_instance.masters.*.id}"]
      }
  }
  </code></pre>
  
  <p>But I don't thing it is working fine, because when I try to write the AWS volumes in a file, it writes only one volume name.</p>
  
  <pre><code>provisioner "local-exec" {
      command =  "echo \"${join("\n", data.aws_ebs_volume.masters_ebs_volume.*.id)}\" &gt;&gt; volumes"
  }
  </code></pre>
  
  <p>I have tried defining the volume like this:</p>
  
  <pre><code>data "aws_ebs_volume" "masters_ebs_volume" {
      count = 2
  #   most_recent = true
      filter {
        name   = "attachment.instance-id"
        values = ["${aws_instance.masters.*.id}"]
      }
  }
  </code></pre>
  
  <p>But it throws the next error: </p>
  
  <pre><code>data.aws_ebs_volume.masters_ebs_volume.0: Your query returned more than one result. Please try a more specific search criteria, or set `most_recent` attribute to true.
  </code></pre>