Docs unclear on how to use variables in vagrantfile.template

I am trying to use a vagrantfile.template file as per the packer spec here: Vagrant Post-Processor | Integrations | Packer | HashiCorp Developer

I have configured a variable in my packer file like so:

{
  "variables": {
    "some_variable": "some_value"
  },
  // ... other configurations ...
}

configuring my vagrant post provisioner like this:

post-processor "vagrant" {
  vagrantfile_template = "path/to/Vagrantfile.template"
}

and trying to interpolate the variable like this in my vagrantfile.template

Vagrant.configure("2") do |config|
  # Use the variable like this:
  config.vm.provider "virtualbox" do |vb|
    vb.name = "{{ user `some_variable` }}"
  end
end

and get the following error:

* Post-processor failed: template: root:17:25: executing "root" at <user `some_variable`>: error calling user: test

The docs are very limited in terms of this functionality - am I doing this right? How is it supposed to work? Does anybody have any working code or implementation details on using this feature?

1 Like