Packer is a great tool to prepare and build virtual machines, but it lacks a feature to build multiple output formats from the same VM in a single run.
For example vagrant, ova, and vhd in one run.
Fortunately, this can be accomplished by writing multiple packer.json files. Which is done the way, that initial VM is provisioned once in the first step, and then kept running. All consequential steps just attach to existing VM and export in desired format, possibly with extra provisioning (vagrant).
The key is to keep VM until the last step. This can be done with "virtualbox-vm" builder and
"keep_registered": true
# content of build.sh
packer setup-vm.json # import ova, or build from iso
packer export-ova.json # export and keep vm
packer export-vhd.json # still keep
packer make-vagrant.json # export and destroy VM
First json:
"builders": [
{
"type": "virtualbox-ovf",
"source_path": "base.ova",
"vm_name": "build-vm",
"keep_registered": true // this is important
...
},
]
Last json:
"builders": [
{
"type": "virtualbox-vm",
"vm_name": "build-vm", // same vm name
"keep_registered": false // finally destroy vm
...
}
],