title: Terraform loop through json file
body: <p>I am trying to spin up a storage account in azurerm using terraform and pair it with a key name to encrypt this storage with. But for commodity and future improvement, I would like to set the name of this storage account from a json file. The idea is to set a array in json with <code>storages name</code> and <code>key_name</code> and in my <code>azurerm_resources</code> loop through those values and set them.</p>
  <p>The issue I am facing is that I am not able to access the json file. I have configured it as follow.</p>
  <p><code>tenant.json</code></p>
  <pre><code>{
    &quot;inputs&quot;: [
          {
            &quot;tenant-pair&quot;: {&quot;tenant-name&quot;:  &quot;storage-name&quot;, &quot;tenant-key&quot;: &quot;key-name&quot;}
          }
        ]
  }
  </code></pre>
  <p>In my main.tf, following some documentations, I set a <code>locals</code> as follow:</p>
  <pre><code>locals {
    tenant_data = jsondecode(&quot;./tenants.json&quot;)
  
  }
  </code></pre>
  <p>but if I try to flatten this data:</p>
  <pre><code>locals {
    tenant_data = jsondecode(&quot;./tenants.json&quot;)
    helper_list = flatten([for v in local.tenant_data.inputs :
      [for tenant_name, tenant_key in v.tenant-pair :
        {
          &quot;tenant_name&quot; = tenant_name
          &quot;tenant_key&quot;  = tenant_key
        }
      ]
    ])
  }
  </code></pre>
  <p>the error I am getting in this code is that the <code>inputs</code> is an unresolved reference.</p>
  <p>I was wondering how I can access my json file and loop through it?</p>
  <p>Thank you very much guys for your help and guidance.</p>