diff --git a/CHANGELOG.md b/CHANGELOG.md index d2f387cd4..89615b49e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,9 @@ FEATURES: Packer will look in the PWD and the directory with `packer` for binaries named `packer-TYPE-NAME`. * builder/docker: Images can now be committed instead of exported. [GH-1198] + * builder/virtualbox-ovf: New `import_flags` setting can be used to add + new command line flags to `VBoxManage import` to allow things such + as EULAs to be accepted. [GH-1383] * builder/vmware: VMware Player 6 is now supported. [GH-1168] IMPROVEMENTS: diff --git a/builder/virtualbox/common/driver.go b/builder/virtualbox/common/driver.go index b95bf81ae..a55b20199 100644 --- a/builder/virtualbox/common/driver.go +++ b/builder/virtualbox/common/driver.go @@ -23,7 +23,7 @@ type Driver interface { Delete(string) error // Import a VM - Import(string, string, string) error + Import(string, string, []string) error // The complete path to the Guest Additions ISO Iso() (string, error) diff --git a/builder/virtualbox/common/driver_4_2.go b/builder/virtualbox/common/driver_4_2.go index 87a0693be..f77b29a57 100644 --- a/builder/virtualbox/common/driver_4_2.go +++ b/builder/virtualbox/common/driver_4_2.go @@ -69,13 +69,13 @@ func (d *VBox42Driver) Iso() (string, error) { return "", fmt.Errorf("Cannot find \"Default Guest Additions ISO\" in vboxmanage output") } -func (d *VBox42Driver) Import(name, path, opts string) error { +func (d *VBox42Driver) Import(name string, path string, flags []string) error { args := []string{ "import", path, "--vsys", "0", "--vmname", name, - "--options", opts, } + args = append(args, flags...) return d.VBoxManage(args...) } diff --git a/builder/virtualbox/common/driver_mock.go b/builder/virtualbox/common/driver_mock.go index 1f7e18487..1aacf9f8f 100644 --- a/builder/virtualbox/common/driver_mock.go +++ b/builder/virtualbox/common/driver_mock.go @@ -16,7 +16,7 @@ type DriverMock struct { ImportCalled bool ImportName string ImportPath string - ImportOpts string + ImportFlags []string ImportErr error IsoCalled bool @@ -55,11 +55,11 @@ func (d *DriverMock) Delete(name string) error { return d.DeleteErr } -func (d *DriverMock) Import(name, path, opts string) error { +func (d *DriverMock) Import(name string, path string, flags []string) error { d.ImportCalled = true d.ImportName = name d.ImportPath = path - d.ImportOpts = opts + d.ImportFlags = flags return d.ImportErr } diff --git a/builder/virtualbox/ovf/builder.go b/builder/virtualbox/ovf/builder.go index 398b34a7a..c41f9a1a4 100644 --- a/builder/virtualbox/ovf/builder.go +++ b/builder/virtualbox/ovf/builder.go @@ -68,9 +68,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe Tpl: b.config.tpl, }, &StepImport{ - Name: b.config.VMName, - SourcePath: b.config.SourcePath, - ImportOpts: b.config.ImportOpts, + Name: b.config.VMName, + SourcePath: b.config.SourcePath, + ImportFlags: b.config.ImportFlags, }, &vboxcommon.StepAttachGuestAdditions{ GuestAdditionsMode: b.config.GuestAdditionsMode, diff --git a/builder/virtualbox/ovf/config.go b/builder/virtualbox/ovf/config.go index a8df48791..4d93a59a0 100644 --- a/builder/virtualbox/ovf/config.go +++ b/builder/virtualbox/ovf/config.go @@ -24,13 +24,14 @@ type Config struct { vboxcommon.VBoxManagePostConfig `mapstructure:",squash"` vboxcommon.VBoxVersionConfig `mapstructure:",squash"` - SourcePath string `mapstructure:"source_path"` - GuestAdditionsMode string `mapstructure:"guest_additions_mode"` - GuestAdditionsPath string `mapstructure:"guest_additions_path"` - GuestAdditionsURL string `mapstructure:"guest_additions_url"` - GuestAdditionsSHA256 string `mapstructure:"guest_additions_sha256"` - VMName string `mapstructure:"vm_name"` - ImportOpts string `mapstructure:"import_opts"` + SourcePath string `mapstructure:"source_path"` + GuestAdditionsMode string `mapstructure:"guest_additions_mode"` + GuestAdditionsPath string `mapstructure:"guest_additions_path"` + GuestAdditionsURL string `mapstructure:"guest_additions_url"` + GuestAdditionsSHA256 string `mapstructure:"guest_additions_sha256"` + VMName string `mapstructure:"vm_name"` + ImportOpts string `mapstructure:"import_opts"` + ImportFlags []string `mapstructure:"import_flags"` tpl *packer.ConfigTemplate } @@ -90,6 +91,21 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) { } } + sliceTemplates := map[string][]string{ + "import_flags": c.ImportFlags, + } + + for n, slice := range sliceTemplates { + for i, elem := range slice { + var err error + slice[i], err = c.tpl.Process(elem, nil) + if err != nil { + errs = packer.MultiErrorAppend( + errs, fmt.Errorf("Error processing %s[%d]: %s", n, i, err)) + } + } + } + if c.SourcePath == "" { errs = packer.MultiErrorAppend(errs, fmt.Errorf("source_path is required")) } else { @@ -147,5 +163,10 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) { return nil, warnings, errs } + // TODO: Write a packer fix and just remove import_opts + if c.ImportOpts != "" { + c.ImportFlags = append(c.ImportFlags, "--options", c.ImportOpts) + } + return c, warnings, nil } diff --git a/builder/virtualbox/ovf/step_import.go b/builder/virtualbox/ovf/step_import.go index 3dc72c174..b9a74c9f8 100644 --- a/builder/virtualbox/ovf/step_import.go +++ b/builder/virtualbox/ovf/step_import.go @@ -9,9 +9,9 @@ import ( // This step imports an OVF VM into VirtualBox. type StepImport struct { - Name string - SourcePath string - ImportOpts string + Name string + SourcePath string + ImportFlags []string vmName string } @@ -21,7 +21,7 @@ func (s *StepImport) Run(state multistep.StateBag) multistep.StepAction { ui := state.Get("ui").(packer.Ui) ui.Say(fmt.Sprintf("Importing VM: %s", s.SourcePath)) - if err := driver.Import(s.Name, s.SourcePath, s.ImportOpts); err != nil { + if err := driver.Import(s.Name, s.SourcePath, s.ImportFlags); err != nil { err := fmt.Errorf("Error importing VM: %s", err) state.Put("error", err) ui.Error(err.Error()) diff --git a/website/source/docs/builders/virtualbox-ovf.html.markdown b/website/source/docs/builders/virtualbox-ovf.html.markdown index 4a41021b2..b9fbf7064 100644 --- a/website/source/docs/builders/virtualbox-ovf.html.markdown +++ b/website/source/docs/builders/virtualbox-ovf.html.markdown @@ -96,6 +96,10 @@ each category, the available options are alphabetized and described. machine being built. When this value is set to true, the machine will start without a console. +* `import_flags` (array of strings) - Additional flags to pass to + `VBoxManage import`. This can be used to add additional command-line flags + such as `--eula-accept` to accept a EULA in the OVF. + * `import_opts` (string) - Additional options to pass to the `VBoxManage import`. This can be useful for passing "keepallmacs" or "keepnatmacs" options for existing ovf images.