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) .
The basic run was
packer build -var-file ubuntu.json template.json
packer build -var-file fedora.json template.json
with -var-file containing a different "boot_command" variable which was assembled from with internal variables. example has pseudo code, just to show the problem and to avoid to show a long line
{
"boot_command": "ubuntu <esc><esc><wait>< preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}"
}
{
"boot_command": "fedora <esc><esc><wait>< url=http://{{ .HTTPIP }}:{{ .HTTPPort }}"
}
I have converted all of this to to hcl.
packer build -var-file fedora.pkr.hcl template.pkr.hcl
packer build -var-file fedora.pkr.hcl template.pkr.hcl
When it try to this in hcl it doesn't allow me to assign strings, which contain variables. The error message is somewhat cryptic "blocks are not allowed here".
locals {
boot_command = [ "ubuntu <esc><esc><wait>< preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}"]
}
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 "ubuntu" to "fedora" as there is no "if ubuntu" then this boot_command content and then another "boot_command"content, as the sequence of keys is of course different with fedora
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?