title: How do I read values of a variable of type Map passed from terraform to powershell userdata script?
body: <p>I need to pass the variable of type map from terraform to powershell userdata script and be able to access the key value pairs of the map in the powershell script. Thank you</p>
  <p><em>userdata.tf</em></p>
  <pre><code>data &quot;template_file&quot; &quot;user_data&quot; {
    template = &quot;${file(&quot;${path.module}/init.ps1&quot;)}&quot;
    vars = {
      environment = var.env
      # I want to pass the values as shown below
      hostnames   = {&quot;dev&quot;:&quot;devhost&quot;,&quot;test&quot;:&quot;testhost&quot;,&quot;prod&quot;:&quot;prodhost&quot;}
    }
  }
  </code></pre>
  <p>init.ps1</p>
  <pre><code>$hostnames = &quot;${hostnames}&quot;
  $environment = &quot;${environment}&quot;
  
  if ($environment -eq &quot;dev&quot;){
     # print the value of the dev key in the hostname map here
  }
  </code></pre>