diff --git a/builder/hyperv/common/step_clone_vm.go b/builder/hyperv/common/step_clone_vm.go index 8233e8306..6ce856cf2 100644 --- a/builder/hyperv/common/step_clone_vm.go +++ b/builder/hyperv/common/step_clone_vm.go @@ -32,6 +32,7 @@ type StepCloneVM struct { EnableVirtualizationExtensions bool MacAddress string KeepRegistered bool + AdditionalDiskSize []uint } func (s *StepCloneVM) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction { @@ -125,6 +126,20 @@ func (s *StepCloneVM) Run(ctx context.Context, state multistep.StateBag) multist } } + if len(s.AdditionalDiskSize) > 0 { + for index, size := range s.AdditionalDiskSize { + diskSize := int64(size * 1024 * 1024) + diskFile := fmt.Sprintf("%s-%d.vhdx", s.VMName, index) + err = driver.AddVirtualMachineHardDrive(s.VMName, path, diskFile, diskSize, diskBlockSize, "SCSI") + if err != nil { + err := fmt.Errorf("Error creating and attaching additional disk drive: %s", err) + state.Put("error", err) + ui.Error(err.Error()) + return multistep.ActionHalt + } + } + } + if s.MacAddress != "" { err = driver.SetVmNetworkAdapterMacAddress(s.VMName, s.MacAddress) if err != nil { diff --git a/builder/hyperv/vmcx/builder.go b/builder/hyperv/vmcx/builder.go index b95630706..d43a36500 100644 --- a/builder/hyperv/vmcx/builder.go +++ b/builder/hyperv/vmcx/builder.go @@ -59,6 +59,14 @@ type Config struct { // Windows installs, which look for an Autounattend.xml file on removable // media. By default, no secondary ISO will be attached. SecondaryDvdImages []string `mapstructure:"secondary_iso_images" required:"false"` + // The size or sizes of any + // additional hard disks for the VM in megabytes. If this is not specified + // then the VM will only contain a primary hard disk. Additional drives + // will be attached to the SCSI interface only. The builder uses + // expandable rather than fixed-size virtual hard disks, so the actual + // file representing the disk will not use the full size unless it is + // full. + AdditionalDiskSize []uint `mapstructure:"disk_additional_size" required:"false"` // If set to attach then attach and // mount the ISO image specified in guest_additions_path. If set to // none then guest additions are not attached and mounted; This is the @@ -67,10 +75,8 @@ type Config struct { // The path to the ISO image for guest // additions. GuestAdditionsPath string `mapstructure:"guest_additions_path" required:"false"` - // This is the path to a directory containing an exported virtual machine. CloneFromVMCXPath string `mapstructure:"clone_from_vmcx_path"` - // This is the name of the virtual machine to clone from. CloneFromVMName string `mapstructure:"clone_from_vm_name"` // The name of a snapshot in the @@ -354,7 +360,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) { } } - numberOfIsos := len(b.config.SecondaryDvdImages) + numberOfIsos := len(b.config.SecondaryDvdImages) + len(b.config.AdditionalDiskSize) if b.config.GuestAdditionsMode == "attach" { if _, err := os.Stat(b.config.GuestAdditionsPath); os.IsNotExist(err) { @@ -524,6 +530,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack EnableVirtualizationExtensions: b.config.EnableVirtualizationExtensions, MacAddress: b.config.MacAddress, KeepRegistered: b.config.KeepRegistered, + AdditionalDiskSize: b.config.AdditionalDiskSize, }, &hypervcommon.StepEnableIntegrationService{},