diff --git a/builder/virtualbox/builder.go b/builder/virtualbox/builder.go index b7bc58c16..18b16867a 100644 --- a/builder/virtualbox/builder.go +++ b/builder/virtualbox/builder.go @@ -32,8 +32,8 @@ type config struct { GuestAdditionsURL string `mapstructure:"guest_additions_url"` GuestAdditionsSHA256 string `mapstructure:"guest_additions_sha256"` GuestOSType string `mapstructure:"guest_os_type"` - Headless bool `mapstructure:"headless"` HardDriveInterface string `mapstructure:"hard_drive_interface"` + Headless bool `mapstructure:"headless"` HTTPDir string `mapstructure:"http_directory"` HTTPPortMin uint `mapstructure:"http_port_min"` HTTPPortMax uint `mapstructure:"http_port_max"` @@ -146,6 +146,7 @@ func (b *Builder) Prepare(raws ...interface{}) error { templates := map[string]*string{ "guest_additions_sha256": &b.config.GuestAdditionsSHA256, "guest_os_type": &b.config.GuestOSType, + "hard_drive_interface": &b.config.HardDriveInterface, "http_directory": &b.config.HTTPDir, "iso_checksum": &b.config.ISOChecksum, "iso_checksum_type": &b.config.ISOChecksumType, @@ -214,6 +215,11 @@ func (b *Builder) Prepare(raws ...interface{}) error { errs, errors.New("invalid format, only 'ovf' or 'ova' are allowed")) } + if b.config.HardDriveInterface != "ide" && b.config.HardDriveInterface != "sata" { + errs = packer.MultiErrorAppend( + errs, errors.New("hard_drive_interface can only be ide or sata")) + } + if b.config.HTTPPortMin > b.config.HTTPPortMax { errs = packer.MultiErrorAppend( errs, errors.New("http_port_min must be less than http_port_max")) diff --git a/builder/virtualbox/builder_test.go b/builder/virtualbox/builder_test.go index 4ea869fef..35ea79bf9 100644 --- a/builder/virtualbox/builder_test.go +++ b/builder/virtualbox/builder_test.go @@ -252,6 +252,38 @@ func TestBuilderPrepare_GuestAdditionsURL(t *testing.T) { } } +func TestBuilderPrepare_HardDriveInterface(t *testing.T) { + var b Builder + config := testConfig() + + // Test a default boot_wait + delete(config, "hard_drive_interface") + err := b.Prepare(config) + if err != nil { + t.Fatalf("err: %s", err) + } + + if b.config.HardDriveInterface != "ide" { + t.Fatalf("bad: %s", b.config.HardDriveInterface) + } + + // Test with a bad + config["hard_drive_interface"] = "fake" + b = Builder{} + err = b.Prepare(config) + if err == nil { + t.Fatal("should have error") + } + + // Test with a good + config["hard_drive_interface"] = "sata" + b = Builder{} + err = b.Prepare(config) + if err != nil { + t.Fatalf("should not have error: %s", err) + } +} + func TestBuilderPrepare_HTTPPort(t *testing.T) { var b Builder config := testConfig() diff --git a/builder/virtualbox/step_create_disk.go b/builder/virtualbox/step_create_disk.go index 80abeeb75..14005cc85 100644 --- a/builder/virtualbox/step_create_disk.go +++ b/builder/virtualbox/step_create_disk.go @@ -51,6 +51,9 @@ func (s *stepCreateDisk) Run(state multistep.StateBag) multistep.StepAction { return multistep.ActionHalt } + // Add a SATA controller if we were asked to use SATA. We still attach + // the IDE controller above because some other things (disks) require + // that. if config.HardDriveInterface == "sata" { controllerName = "SATA Controller" command = []string{