diff --git a/builder/vmware/builder.go b/builder/vmware/builder.go index c61237136..e9677557e 100644 --- a/builder/vmware/builder.go +++ b/builder/vmware/builder.go @@ -26,6 +26,7 @@ type Builder struct { type config struct { DiskName string `mapstructure:"vmdk_name"` + DiskSize uint `mapstructure:"disk_size"` GuestOSType string `mapstructure:"guest_os_type"` ISOMD5 string `mapstructure:"iso_md5"` ISOUrl string `mapstructure:"iso_url"` @@ -65,6 +66,10 @@ func (b *Builder) Prepare(raws ...interface{}) error { b.config.DiskName = "disk" } + if b.config.DiskSize == 0 { + b.config.DiskSize = 40000 + } + if b.config.GuestOSType == "" { b.config.GuestOSType = "other" } diff --git a/builder/vmware/builder_test.go b/builder/vmware/builder_test.go index 1d386fb03..b246a118b 100644 --- a/builder/vmware/builder_test.go +++ b/builder/vmware/builder_test.go @@ -68,6 +68,32 @@ func TestBuilderPrepare_Defaults(t *testing.T) { } } +func TestBuilderPrepare_DiskSize(t *testing.T) { + var b Builder + config := testConfig() + + delete(config, "disk_size") + err := b.Prepare(config) + if err != nil { + t.Fatalf("bad err: %s", err) + } + + if b.config.DiskSize != 40000 { + t.Fatalf("bad size: %d", b.config.DiskSize) + } + + config["disk_size"] = 60000 + b = Builder{} + err = b.Prepare(config) + if err != nil { + t.Fatalf("should not have error: %s", err) + } + + if b.config.DiskSize != 60000 { + t.Fatalf("bad size: %s", b.config.DiskSize) + } +} + func TestBuilderPrepare_HTTPPort(t *testing.T) { var b Builder config := testConfig() diff --git a/builder/vmware/step_create_disk.go b/builder/vmware/step_create_disk.go index 61f578127..7624224d0 100644 --- a/builder/vmware/step_create_disk.go +++ b/builder/vmware/step_create_disk.go @@ -19,16 +19,13 @@ import ( type stepCreateDisk struct{} func (stepCreateDisk) Run(state map[string]interface{}) multistep.StepAction { - // TODO(mitchellh): Configurable disk size - // TODO(mitchellh): Capture error output in case things go wrong to report it - config := state["config"].(*config) driver := state["driver"].(Driver) ui := state["ui"].(packer.Ui) ui.Say("Creating virtual machine disk") output := filepath.Join(config.OutputDir, config.DiskName+".vmdk") - if err := driver.CreateDisk(output, "40000M"); err != nil { + if err := driver.CreateDisk(output, fmt.Sprintf("%dM", config.DiskSize)); err != nil { err := fmt.Errorf("Error creating disk: %s", err) state["error"] = err ui.Error(err.Error())