diff --git a/CHANGELOG.md b/CHANGELOG.md index 71ad528e7..c04bc7642 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ IMPROVEMENTS: BUG FIXES: +* vagrant: The `BuildName` template propery works properly in + the output path. * vagrant: Properly configure the provider-specific post-processors so things like `vagrantfile_template` work. [GH-129] diff --git a/post-processor/vagrant/aws.go b/post-processor/vagrant/aws.go index ae5de6ac9..747207832 100644 --- a/post-processor/vagrant/aws.go +++ b/post-processor/vagrant/aws.go @@ -105,6 +105,7 @@ func (p *AWSBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact // Compress the directory to the given output path if err := DirToBox(outputPath, dir); err != nil { + err = fmt.Errorf("error creating box: %s", err) return nil, false, err } diff --git a/post-processor/vagrant/post-processor.go b/post-processor/vagrant/post-processor.go index 8446b9a5c..0ad450dc8 100644 --- a/post-processor/vagrant/post-processor.go +++ b/post-processor/vagrant/post-processor.go @@ -40,8 +40,10 @@ func (p *PostProcessor) Configure(raws ...interface{}) error { } } + ppExtraConfig := make(map[string]interface{}) if p.config.OutputPath == "" { p.config.OutputPath = "packer_{{ .BuildName }}_{{.Provider}}.box" + ppExtraConfig["output"] = p.config.OutputPath } _, err := template.New("output").Parse(p.config.OutputPath) @@ -49,16 +51,15 @@ func (p *PostProcessor) Configure(raws ...interface{}) error { return fmt.Errorf("output invalid template: %s", err) } + // Store the extra configuration for post-processors + p.rawConfigs = append(p.rawConfigs, ppExtraConfig) + // TODO(mitchellh): Properly handle multiple raw configs var mapConfig map[string]interface{} if err := mapstructure.Decode(raws[0], &mapConfig); err != nil { return err } - packerConfig := map[string]interface{}{ - packer.BuildNameConfigKey: p.config.PackerBuildName, - } - p.premade = make(map[string]packer.PostProcessor) errors := make([]error, 0) for k, raw := range mapConfig { @@ -67,7 +68,12 @@ func (p *PostProcessor) Configure(raws ...interface{}) error { continue } - if err := pp.Configure(raw, packerConfig); err != nil { + // Create the proper list of configurations + ppConfigs := make([]interface{}, 0, len(p.rawConfigs)+1) + copy(ppConfigs, p.rawConfigs) + ppConfigs = append(ppConfigs, raw) + + if err := pp.Configure(ppConfigs...); err != nil { errors = append(errors, err) } diff --git a/post-processor/vagrant/util.go b/post-processor/vagrant/util.go index fa6ee8f25..5966008c5 100644 --- a/post-processor/vagrant/util.go +++ b/post-processor/vagrant/util.go @@ -25,7 +25,7 @@ type OutputPathTemplate struct { // box. This function does not perform checks to verify that dir is // actually a proper box. This is an expected precondition. func DirToBox(dst, dir string) error { - log.Printf("Turning dir into box: %s", dir) + log.Printf("Turning dir into box: %s => %s", dir, dst) dstF, err := os.Create(dst) if err != nil { return err