title: How to define a list in Terraform that may be empty depending on a variable?
body: <p>I need to define a resource in Terraform (v0.10.8) that has a list property that may or may not be empty depending on a variable, see <code>volume_ids</code> in the following definition:</p>
  
  <pre><code>resource "digitalocean_droplet" "worker_node" {
    count = "${var.droplet_count}"
    [...]
    volume_ids = [
      "${var.volume_size != 0 ? element(digitalocean_volume.worker.*.id, count.index) : ""}"
    ]
  }
  
  resource "digitalocean_volume" "worker" {
    count = "${var.volume_size != 0 ? var.droplet_count : 0}"
    [...]
  }
  </code></pre>
  
  <p>}</p>
  
  <p>The solution I've come up with fails however in the case where the list should be empty (i.e., <code>var.volume_size</code> is 0):</p>
  
  <pre><code>volume_ids = [
    "${var.volume_size != 0 ? element(digitalocean_volume.worker.*.id, count.index) : ""}"
  ]
  </code></pre>
  
  <p>The following Terraform error message is produced:</p>
  
  <pre><code>* module.workers.digitalocean_droplet.worker_node[1]: element: element() may not be used with an empty list in:
  
  ${var.volume_size != 0 ? element(digitalocean_volume.worker.*.id, count.index) : ""}
  </code></pre>
  
  <p>How should I correctly write my definition of <code>volume_ids</code>?</p>