From 13cc2071161b91fba5f4d49eeca651d524ce684e Mon Sep 17 00:00:00 2001 From: Fedor Korotkov Date: Tue, 20 Sep 2022 09:51:32 -0400 Subject: [PATCH] Respect disk size upon creation (#23) Related to https://github.com/cirruslabs/macos-image-templates/pull/55 --- builder/tart/step_create_vm.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/builder/tart/step_create_vm.go b/builder/tart/step_create_vm.go index c35dbdb..6d2af56 100644 --- a/builder/tart/step_create_vm.go +++ b/builder/tart/step_create_vm.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/hashicorp/packer-plugin-sdk/multistep" packersdk "github.com/hashicorp/packer-plugin-sdk/packer" + "strconv" ) type stepCreateVM struct{} @@ -15,7 +16,17 @@ func (s *stepCreateVM) Run(ctx context.Context, state multistep.StateBag) multis ui.Say("Creating virtual machine...") - if _, err := TartExec("create", "--from-ipsw", config.FromIPSW, config.VMName); err != nil { + createArguments := []string{ + "create", "--from-ipsw", config.FromIPSW, + } + + if config.DiskSizeGb > 0 { + createArguments = append(createArguments, "--disk-size", strconv.Itoa(int(config.DiskSizeGb))) + } + + createArguments = append(createArguments, config.VMName) + + if _, err := TartExec(createArguments...); err != nil { err := fmt.Errorf("Failed to create a VM: %s", err) state.Put("error", err) ui.Error(err.Error())