title: Terraform get the length of list
body: <p>I'm experimenting with Terraform and I came across <strong>locals</strong>. What I'm trying to do is to get the length of the list based on another varibale (<strong>env</strong>).</p>
  
  <p>how can to make terrform to evaluate the variable before getting trying to evaluate the length?</p>
  
  <p>This is my code:</p>
  
  <pre><code>locals {
    env = "${terraform.workspace}"
  
    subnet_names = {
      "default" = ["default_sub1"]
      "dev"     = ["dev_sub1", "dev_sub2", "dev_sub3"]
      "prod"    = ["prod_sub1", "prod_sub2", "prod_sub3"]
    }
  
  }
  
  resource "azurerm_subnet" "subnet" {
    name                      = "${lookup(local.subnet_names, local.env, count.index)}"
    virtual_network_name      = "${azurerm_virtual_network.network.name}"
    resource_group_name       = "${azurerm_resource_group.terraform.name}"
    address_prefix            = "10.0.1.0/24"
    network_security_group_id = "${azurerm_network_security_group.security_group.id}"
    count                     =  "${length(local.subnet_names, local.env)}"
  }
  </code></pre>
  
  <p>When I try to validate the code I get this <code>length: expected 1 arguments, got 2 in</code>: <code>${length(local.subnet_names, local.env)}</code> </p>
  
  <p>What is the trick here?</p>