hashicorp / packer-plugin-virtualbox

Packer plugin for VritualBox Builder
https://www.packer.io/docs/builders/virtualbox
Mozilla Public License 2.0
22 stars 36 forks source link

Support .vhd file #124

Open remi-espie opened 6 months ago

remi-espie commented 6 months ago

This PR adds support for .vhd files.

Before this PR, when using a .vhd as the iso_url (as stated possible in the documentation), VirtualBox returns the error Error attaching ISO: VBoxManage error: VBoxManage.exe: error: The medium '<path/to/vhd>' can't be used as the requested device type (DVD, detected HDD).

This solves the issue by checking the extension of the file and, if it is .vhd, by changing the disk type from dvddrive to hdd in the VirtualBox' VM creation command. If using a hdd type disk, it will not be unmounted before export. It also removes the creation of a .vdi disk if using a .vhd.

However, by using directly the .vhd file, it is modified and won't remain the same after running packer. An improvement would be to clone the .vhd file to the temp directory, as (for example) the Hyper-V plugin do.

This closes #123

hashicorp-cla-app[bot] commented 2 months ago

CLA assistant check
All committers have signed the CLA.

remi-espie commented 2 months ago

With the latest commit, the source .vhd file is copied to a temporary directory randomly named with your tmp.Dir function, and the job is done on this copy.

The copy takes place during the attach_isos step of the common builder. I thought it made sense to put it here as it is where the file extension is also checked, and it made the modifications minimal.

As always, thanks for your review !