diff --git a/builder/virtualbox/common/vbox_version_config.go b/builder/virtualbox/common/vbox_version_config.go index 9f1479445..5ece4d12a 100644 --- a/builder/virtualbox/common/vbox_version_config.go +++ b/builder/virtualbox/common/vbox_version_config.go @@ -5,12 +5,13 @@ import ( ) type VBoxVersionConfig struct { - VBoxVersionFile string `mapstructure:"virtualbox_version_file"` + VBoxVersionFile *string `mapstructure:"virtualbox_version_file"` } func (c *VBoxVersionConfig) Prepare(ctx *interpolate.Context) []error { - if c.VBoxVersionFile == "" { - c.VBoxVersionFile = ".vbox_version" + if c.VBoxVersionFile == nil { + default_file := ".vbox_version" + c.VBoxVersionFile = &default_file } return nil diff --git a/builder/virtualbox/common/vbox_version_config_test.go b/builder/virtualbox/common/vbox_version_config_test.go index d4cc85565..811ba60ff 100644 --- a/builder/virtualbox/common/vbox_version_config_test.go +++ b/builder/virtualbox/common/vbox_version_config_test.go @@ -15,19 +15,50 @@ func TestVBoxVersionConfigPrepare_BootWait(t *testing.T) { t.Fatalf("should not have error: %s", errs) } - if c.VBoxVersionFile != ".vbox_version" { - t.Fatalf("bad value: %s", c.VBoxVersionFile) + if *c.VBoxVersionFile != ".vbox_version" { + t.Fatalf("bad value: %s", *c.VBoxVersionFile) } // Test with a good one c = new(VBoxVersionConfig) - c.VBoxVersionFile = "foo" + filename := "foo" + c.VBoxVersionFile = &filename errs = c.Prepare(testConfigTemplate(t)) if len(errs) > 0 { t.Fatalf("should not have error: %s", errs) } - if c.VBoxVersionFile != "foo" { - t.Fatalf("bad value: %s", c.VBoxVersionFile) + if *c.VBoxVersionFile != "foo" { + t.Fatalf("bad value: %s", *c.VBoxVersionFile) + } +} + +func TestVBoxVersionConfigPrepare_empty(t *testing.T) { + var c *VBoxVersionConfig + var errs []error + + // Test with nil value + c = new(VBoxVersionConfig) + c.VBoxVersionFile = nil + errs = c.Prepare(testConfigTemplate(t)) + if len(errs) > 0 { + t.Fatalf("should not have error: %s", errs) + } + + if *c.VBoxVersionFile != ".vbox_version" { + t.Fatalf("bad value: %s", *c.VBoxVersionFile) + } + + // Test with empty name + c = new(VBoxVersionConfig) + filename := "" + c.VBoxVersionFile = &filename + errs = c.Prepare(testConfigTemplate(t)) + if len(errs) > 0 { + t.Fatalf("should not have error: %s", errs) + } + + if *c.VBoxVersionFile != "" { + t.Fatalf("bad value: %s", *c.VBoxVersionFile) } } diff --git a/builder/virtualbox/iso/builder.go b/builder/virtualbox/iso/builder.go index abe32590c..f9def2528 100644 --- a/builder/virtualbox/iso/builder.go +++ b/builder/virtualbox/iso/builder.go @@ -246,7 +246,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe WinRMPort: vboxcommon.SSHPort, }, &vboxcommon.StepUploadVersion{ - Path: b.config.VBoxVersionFile, + Path: *b.config.VBoxVersionFile, }, &vboxcommon.StepUploadGuestAdditions{ GuestAdditionsMode: b.config.GuestAdditionsMode, diff --git a/builder/virtualbox/ovf/builder.go b/builder/virtualbox/ovf/builder.go index b7d42183e..9607a0717 100644 --- a/builder/virtualbox/ovf/builder.go +++ b/builder/virtualbox/ovf/builder.go @@ -119,7 +119,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe WinRMPort: vboxcommon.SSHPort, }, &vboxcommon.StepUploadVersion{ - Path: b.config.VBoxVersionFile, + Path: *b.config.VBoxVersionFile, }, &vboxcommon.StepUploadGuestAdditions{ GuestAdditionsMode: b.config.GuestAdditionsMode, diff --git a/website/source/docs/builders/virtualbox-iso.html.md b/website/source/docs/builders/virtualbox-iso.html.md index bd6df7151..9678fc38e 100644 --- a/website/source/docs/builders/virtualbox-iso.html.md +++ b/website/source/docs/builders/virtualbox-iso.html.md @@ -304,7 +304,8 @@ builder. upload a file that contains the VirtualBox version that was used to create the machine. This information can be useful for provisioning. By default this is ".vbox\_version", which will generally be upload it into the - home directory. + home directory. Set to an empty string to skip uploading this file, which + can be useful when using the `none` communicator. - `vm_name` (string) - This is the name of the OVF file for the new virtual machine, without the file extension. By default this is "packer-BUILDNAME", diff --git a/website/source/docs/builders/virtualbox-ovf.html.md b/website/source/docs/builders/virtualbox-ovf.html.md index feef4ffae..f210c3c4b 100644 --- a/website/source/docs/builders/virtualbox-ovf.html.md +++ b/website/source/docs/builders/virtualbox-ovf.html.md @@ -266,7 +266,8 @@ builder. upload a file that contains the VirtualBox version that was used to create the machine. This information can be useful for provisioning. By default this is ".vbox\_version", which will generally be upload it into the - home directory. + home directory. Set to an empty string to skip uploading this file, which + can be useful when using the `none` communicator. - `vm_name` (string) - This is the name of the virtual machine when it is imported as well as the name of the OVF file when the virtual machine