From e44fa1ab9000bc912a728fe132d2ed8b68acc8a8 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 27 Jun 2013 07:38:33 -0700 Subject: [PATCH] post-processor/vagrant: Ability to specify Vagrantfile template --- post-processor/vagrant/post-processor.go | 3 +-- post-processor/vagrant/virtualbox.go | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/post-processor/vagrant/post-processor.go b/post-processor/vagrant/post-processor.go index ebb8677ab..16630df18 100644 --- a/post-processor/vagrant/post-processor.go +++ b/post-processor/vagrant/post-processor.go @@ -16,11 +16,10 @@ var builtins = map[string]string{ type Config struct { OutputPath string `mapstructure:"output"` - } type PostProcessor struct { - config Config + config Config premade map[string]packer.PostProcessor } diff --git a/post-processor/vagrant/virtualbox.go b/post-processor/vagrant/virtualbox.go index 766e86c8d..c76726629 100644 --- a/post-processor/vagrant/virtualbox.go +++ b/post-processor/vagrant/virtualbox.go @@ -12,7 +12,8 @@ import ( ) type VBoxBoxConfig struct { - OutputPath string `mapstructure:"output"` + OutputPath string `mapstructure:"output"` + VagrantfileTemplate string `mapstructure:"vagrantfile_template"` } type VBoxVagrantfileTemplate struct { @@ -70,7 +71,23 @@ func (p *VBoxBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifac } defer vf.Close() - t := template.Must(template.New("vagrantfile").Parse(defaultVBoxVagrantfile)) + vagrantfileContents := defaultVBoxVagrantfile + if p.config.VagrantfileTemplate != "" { + f, err := os.Open(p.config.VagrantfileTemplate) + if err != nil { + return nil, err + } + defer f.Close() + + contents, err := ioutil.ReadAll(f) + if err != nil { + return nil, err + } + + vagrantfileContents = string(contents) + } + + t := template.Must(template.New("vagrantfile").Parse(vagrantfileContents)) t.Execute(vf, tplData) vf.Close()