title: Terraform looking local vars that are calculated using mapping when using count to create multiple resources
body: <p>I’m using mapped variables in order to create local vars based on longer variable names, I'm using them where we would have abbreviations or where the resource wants a sanitized or shortened version of a value used elsewhere.</p>
  
  <p>Eg</p>
  
  <pre><code>variable "env-short" {
    description = "create a shortened version of the name of use in resource naming"
    type        = "map"
    default = {
      "Proof Of Concept"        = "poc"
      "User Acceptance Testing" = "uat"
      "Production"              = "prd"
    }
  }
  variable "org-short" {
    description = "create a shortened version of the name of use in resource naming"
    type        = map(string)
    default = {
      "My Big Company" = "MBC"
      "My Little Company"    = "MLC"
    }
  }
  variable "loc-short" {
    description = "create a shortened version of the name of use in resource naming"
    type        = map(string)
    default = {
      "UK South"     = "UKS"
      "UK West"      = "UKW"
      "North Europe" = "NEU"
      "West Europe"  = "WEU"
    }
  }
  </code></pre>
  
  <p>And use corresponding variables for their full length mapping equiverlants.</p>
  
  <p>Now I could use as is within a resource block by something like</p>
  
  <pre><code>Name = “${lower(“${var.loc-short[$var.location]}”)-${lower(“${var.org-short[$var.organisation]}”)-${lower(“${var.env-short[$var.environment]}”)-myresource”
  </code></pre>
  
  <p>But like all good coders I like to keep things neat and readable by declaring local variables that I can then refer to.</p>
  
  <pre><code>locals {
    org-short           = "${lower("${var.org-short["${var.organisation}"]}")}"
    loc-short           = "${lower("${var.loc-short["${var.location}"]}")}"
    env-short           = "${lower("${var.env-short["${var.environment}"]}")}"
    #                      I also create additional for commonly used configurations of them
    name-prefix         = "${lower("${var.org-short["${var.organisation}"]}")}-${lower("${var.loc-short["${var.location}"]}")}"
    name-prefix-storage = "${lower("${var.org-short["${var.organisation}"]}")}${lower("${var.loc-short["${var.location}"]}")}"
  }
  </code></pre>
  
  <p>This works really great and keeps things neat tidy and readable.</p>
  
  <pre><code>resource "provisioner_example" "test" {
    location   = var.location
    name       = “${local.loc-short}-${local.env-short}-my resource”
  </code></pre>
  
  <p>I would like however to be able to use this format when I start creating multiple resources using the count functionality.</p>
  
  <pre><code>resource "provisioner_example" "test" {
    count      = length(var.location)
    location   = var.location[count.index]
    name       = “${local.loc-short[count.index]}-${local.env-short}-my resource”
  </code></pre>
  
  <p>Terraform then complains that the index is invalid in the locals lookup,  varlocation is tuple with 2 elements,| var.loc-short is map of string with 4 elements.  The given key does not identify an element in this collection value: string required.</p>
  
  <p>Now I know I can work around this by  getting rid of the locals variables andincluding the variable calculation directly </p>
  
  <pre><code>name =”${lower("${var.loc-short["${var.locations[count.index]}"]}")}-${local.env-short}-my resource"
  </code></pre>
  
  <p>But to me it then makes the code seem more messy and less structured.
  Any ideas on how I can pass the count index value to the map lookup?</p>