diff --git a/builder/virtualbox/ovf/builder.go b/builder/virtualbox/ovf/builder.go index 22934048d..fffd90530 100644 --- a/builder/virtualbox/ovf/builder.go +++ b/builder/virtualbox/ovf/builder.go @@ -48,6 +48,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe Files: b.config.FloppyFiles, }, &StepImport{ + Name: b.config.VMName, SourcePath: b.config.SourcePath, }, /* diff --git a/builder/virtualbox/ovf/config.go b/builder/virtualbox/ovf/config.go index e1272f1ac..853b81333 100644 --- a/builder/virtualbox/ovf/config.go +++ b/builder/virtualbox/ovf/config.go @@ -1,6 +1,7 @@ package ovf import ( + "fmt" vboxcommon "github.com/mitchellh/packer/builder/virtualbox/common" "github.com/mitchellh/packer/common" "github.com/mitchellh/packer/packer" @@ -19,6 +20,7 @@ type Config struct { vboxcommon.VBoxVersionConfig `mapstructure:",squash"` SourcePath string `mapstructure:"source_path"` + VMName string `mapstructure:"vm_name"` tpl *packer.ConfigTemplate } @@ -36,6 +38,11 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) { } c.tpl.UserVars = c.PackerUserVars + // Defaults + if c.VMName == "" { + c.VMName = fmt.Sprintf("packer-%s-{{timestamp}}", c.PackerBuildName) + } + // Prepare the errors errs := common.CheckUnusedConfig(md) errs = packer.MultiErrorAppend(errs, c.ExportConfig.Prepare(c.tpl)...) @@ -46,6 +53,19 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) { errs = packer.MultiErrorAppend(errs, c.VBoxManageConfig.Prepare(c.tpl)...) errs = packer.MultiErrorAppend(errs, c.VBoxVersionConfig.Prepare(c.tpl)...) + templates := map[string]*string{ + "vm_name": &c.VMName, + } + + for n, ptr := range templates { + var err error + *ptr, err = c.tpl.Process(*ptr, nil) + if err != nil { + errs = packer.MultiErrorAppend( + errs, fmt.Errorf("Error processing %s: %s", n, err)) + } + } + // Warnings var warnings []string if c.ShutdownCommand == "" {