hashicorp / packer-plugin-hyperv

Packer plugin for Hyper-V Builder
https://www.packer.io/docs/builders/hyperv
Mozilla Public License 2.0
19 stars 23 forks source link

Enhance hyperv-vmcx builder to resize VHDX files #63

Closed japicken closed 1 year ago

japicken commented 2 years ago

Description

Would like to be able to specify a new disk_size when cloning an existing vmcx. There are instances where we create a very small base Windows image and clone it for various roles, which have different needs in terms of the size of the primary disk. I should be able to clone the same 'base image' in multiple packer builds and tweak (increase) the size of the primary drive as needed.

Use Case(s)

source "hyperv-vmcx" "hyperv" {
  ...
  clone_file_vmcx_path: "Windows10_Image_With_32GB_Primary_Disk"
  disk_size: 500 *1024
}

Packer should import the VM, but before starting it, it should run something to the effect of the powershell commands below:

Get-VHD -Path $pathToClonedVHD | Resize-VHD -SizeInBytes ($disk_size * 1024 *1024)

Of course to make that useful space, it would be left to the user to run a provisioner within the guest OS to expand the C: drive.