title: packer hcl2 how to use locals in -var-file or alternative pattern
body: <p>in my original json for packer it was easy to assemble variables which reference other variables.
  Now that packer recommends to use hcl2 i am wondering how to use this pattern (or antipattern in hcl2) .</p>
  <p>The basic run was</p>
  <pre><code>packer build -var-file ubuntu.json template.json
  packer build -var-file fedora.json template.json
  </code></pre>
  <p>with -var-file containing a different &quot;boot_command&quot; variable which was assembled from with internal variables.  <em>example has pseudo code, just to show the problem and to avoid to show a long line</em></p>
  <pre><code>{
    &quot;boot_command&quot;: &quot;ubuntu &lt;esc&gt;&lt;esc&gt;&lt;wait&gt;&lt; preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}&quot;
  }
  
  {
    &quot;boot_command&quot;: &quot;fedora &lt;esc&gt;&lt;esc&gt;&lt;wait&gt;&lt; url=http://{{ .HTTPIP }}:{{ .HTTPPort }}&quot;
  }
  </code></pre>
  <p>I have converted all of this to to hcl.</p>
  <pre><code>packer build -var-file fedora.pkr.hcl template.pkr.hcl
  packer build -var-file fedora.pkr.hcl template.pkr.hcl
  </code></pre>
  <p>When it try to this in hcl it doesn't allow me to assign strings, which contain variables. The error message is somewhat cryptic &quot;<strong>blocks are not allowed here&quot;.</strong></p>
  <pre><code>locals {
    boot_command = [ &quot;ubuntu &lt;esc&gt;&lt;esc&gt;&lt;wait&gt;&lt; preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}&quot;]
  }
  </code></pre>
  <p>I am wondering how this is done in hcl2 correctly, because when I put the locals section into the template.pkr.hcl as follows, it works, but now i am wondering how i could switch from &quot;ubuntu&quot; to &quot;fedora&quot; as there is no &quot;if ubuntu&quot; then this boot_command content and then another &quot;boot_command&quot;content, as the sequence  of keys is of course different with fedora</p>
  <p>How would i do this correctly in hcl2, or is the consequence that i need to maintain two copies of the template.pkr.hcl  only to have different boot_commands?</p>