Templating user variables into boot_command

Hey all, does anyone know if there is any documentation or examples for plugging user variables into a boot_command using the VirtualBox provisioner? I know Packer has a couple magic variables for serving up things like kickstart files (.HTTPIP and .HTTPPort), but I’m not sure how to substitute user variables in the same way. The syntax I keep seeing is {user variable}, but I get this error when I try that during a build

Build ‘virtualbox-iso.opnsense’ errored after 14 seconds 935 milliseconds: Error preparing boot command: template: root:1:58: executing “root” at <user foo>: error calling user: test

Anyone know what I’m doing wrong?

It is double curly brackets and the variable in backticks.

{{ user `vm_boot_command` }}

That doesn’t appear to be working
boot_command = ["{{ user `foo` }}"]

==> virtualbox-iso.opnsense: Error preparing boot command: template: root:1:11: executing “root” at : error calling user: test
Also not sure if it’s relevant, but I’m using HCL spec files instead of JSON. Packer version is 1.6.6

HCL is another approach. Have you read the documentation?

1 Like

Huh, I searched through the docs a few times and never saw this guide, guess I must have missed it. Looks like the syntax for HCL is different, more akin to traditional bash interpolation e.g. ${var.sudo_password}

That works for me, thanks for pointing that out.

1 Like

Could you share your config, please?