diff --git a/builder/virtualbox/common/output_config.go b/builder/virtualbox/common/output_config.go index e99919dcb..aedfa5cf7 100644 --- a/builder/virtualbox/common/output_config.go +++ b/builder/virtualbox/common/output_config.go @@ -17,6 +17,10 @@ type OutputConfig struct { // the builder. By default this is output-BUILDNAME where "BUILDNAME" is the // name of the build. OutputDir string `mapstructure:"output_directory" required:"false"` + // This is the base name of the file (excluding the file extension) where + // the resulting virtual machine will be created. By default this is the + // `vm_name`. + OutputFilename string `mapstructure:"output_filename" required:"false"` } func (c *OutputConfig) Prepare(ctx *interpolate.Context, pc *common.PackerConfig) []error { diff --git a/builder/virtualbox/common/step_export.go b/builder/virtualbox/common/step_export.go index 57e5bed2f..7a3dd13f4 100644 --- a/builder/virtualbox/common/step_export.go +++ b/builder/virtualbox/common/step_export.go @@ -19,6 +19,7 @@ import ( type StepExport struct { Format string OutputDir string + OutputFilename string ExportOpts []string Bundling VBoxBundleConfig SkipNatMapping bool @@ -37,6 +38,9 @@ func (s *StepExport) Run(ctx context.Context, state multistep.StateBag) multiste driver := state.Get("driver").(Driver) ui := state.Get("ui").(packer.Ui) vmName := state.Get("vmName").(string) + if s.OutputFilename == "" { + s.OutputFilename = vmName + } // Skip export if requested if s.SkipExport { @@ -61,7 +65,7 @@ func (s *StepExport) Run(ctx context.Context, state multistep.StateBag) multiste } // Export the VM to an OVF - outputPath := filepath.Join(s.OutputDir, vmName+"."+s.Format) + outputPath := filepath.Join(s.OutputDir, s.OutputFilename+"."+s.Format) command := []string{ "export", diff --git a/builder/virtualbox/iso/builder.go b/builder/virtualbox/iso/builder.go index a52837203..805e4a287 100644 --- a/builder/virtualbox/iso/builder.go +++ b/builder/virtualbox/iso/builder.go @@ -396,6 +396,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack &vboxcommon.StepExport{ Format: b.config.Format, OutputDir: b.config.OutputDir, + OutputFilename: b.config.OutputFilename, ExportOpts: b.config.ExportConfig.ExportOpts, Bundling: b.config.VBoxBundleConfig, SkipNatMapping: b.config.SkipNatMapping, diff --git a/builder/virtualbox/ovf/builder.go b/builder/virtualbox/ovf/builder.go index ab4b524cc..9ee156748 100644 --- a/builder/virtualbox/ovf/builder.go +++ b/builder/virtualbox/ovf/builder.go @@ -158,6 +158,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack &vboxcommon.StepExport{ Format: b.config.Format, OutputDir: b.config.OutputDir, + OutputFilename: b.config.OutputFilename, ExportOpts: b.config.ExportConfig.ExportOpts, SkipNatMapping: b.config.SkipNatMapping, SkipExport: b.config.SkipExport, diff --git a/builder/virtualbox/vm/builder.go b/builder/virtualbox/vm/builder.go index f8f493d60..2efa4d37a 100644 --- a/builder/virtualbox/vm/builder.go +++ b/builder/virtualbox/vm/builder.go @@ -141,6 +141,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack &vboxcommon.StepExport{ Format: b.config.Format, OutputDir: b.config.OutputDir, + OutputFilename: b.config.OutputFilename, ExportOpts: b.config.ExportOpts, SkipNatMapping: b.config.SkipNatMapping, SkipExport: b.config.SkipExport,