September 13, 2018

New VA From an Existing One With Packer

When deploying Virtual Appliances (VA), you want the process to be automated and repeatable, not just a one shot configured and exported manually. Thanks to Packer, automating this is just a question of creating a JSON configuration file and letting it do its magic.

Packer is used by giving it an ISO image of a base distribution, installing the distribution and running the modifications you want. This is good when creating new VAs, but what can you do if you already have an existing one?

Using the QEMU builder, you can actually use a previous image, in qcow2 or img format, by passing the path of the image in iso_url and setting disk_image to true. This would make the simplest builder look like the following (may be missing options):

	"type": "qemu",
	"iso_url": "./my_old_va.qcow2",
	"iso_checksum": "b2bb930f08bb1623f302544cbc94acbd5a919e3aca1a098a29928c827bbff2ab",
	"iso_checksum_type": "sha256",
	"disk_image": true,
	"vm_name": "my_new_va.qcow2"

This process is repeatable as long as you precise the checksum of the initial image to Packer, thus ensuring you always start with the same.

I would however only advise to use this process in case you already have the previous generation step precisely defined, or even better automated. If not, you may end up with an image that contains extra you do not even know are here, which may lead to unexpected behaviour.

You may not really have a choice in this if you are left with appliances that have no explicit build process. In that case, automating fixes or development like this is the best way to make sure anyone coming after you can easily reproduce, and even understand, what was done.

Copyright Marin Gilles 2019-2021