Commit 2302e90a authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

Merge pull request #329 from jasonberanek/vagrant-output-fix

post-processor/vagrant: proper output ConfigTemplate validation [GH-324]
parents aeb395fe 0e336578
...@@ -6,9 +6,9 @@ package vagrant ...@@ -6,9 +6,9 @@ package vagrant
import ( import (
"fmt" "fmt"
"github.com/mitchellh/mapstructure" "github.com/mitchellh/mapstructure"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
"log" "log"
"text/template"
) )
var builtins = map[string]string{ var builtins = map[string]string{
...@@ -18,6 +18,8 @@ var builtins = map[string]string{ ...@@ -18,6 +18,8 @@ var builtins = map[string]string{
} }
type Config struct { type Config struct {
common.PackerConfig `mapstructure:",squash"`
OutputPath string `mapstructure:"output"` OutputPath string `mapstructure:"output"`
} }
...@@ -31,12 +33,19 @@ func (p *PostProcessor) Configure(raws ...interface{}) error { ...@@ -31,12 +33,19 @@ func (p *PostProcessor) Configure(raws ...interface{}) error {
// Store the raw configs for usage later // Store the raw configs for usage later
p.rawConfigs = raws p.rawConfigs = raws
for _, raw := range raws { md, err := common.DecodeConfig(&p.config, raws...)
err := mapstructure.Decode(raw, &p.config) if err != nil {
if err != nil { return err
return err }
}
tpl, err := packer.NewConfigTemplate()
if err != nil {
return err
} }
tpl.UserVars = p.config.PackerUserVars
// Accumulate any errors
errs := common.CheckUnusedConfig(md)
ppExtraConfig := make(map[string]interface{}) ppExtraConfig := make(map[string]interface{})
if p.config.OutputPath == "" { if p.config.OutputPath == "" {
...@@ -44,9 +53,11 @@ func (p *PostProcessor) Configure(raws ...interface{}) error { ...@@ -44,9 +53,11 @@ func (p *PostProcessor) Configure(raws ...interface{}) error {
ppExtraConfig["output"] = p.config.OutputPath ppExtraConfig["output"] = p.config.OutputPath
} }
_, err := template.New("output").Parse(p.config.OutputPath) // _, err := template.New("output").Parse(p.config.OutputPath)
if err != nil { if err := tpl.Validate(p.config.OutputPath); err != nil {
return fmt.Errorf("output invalid template: %s", err) errs = packer.MultiErrorAppend(
errs, fmt.Errorf("Error parsing output template: %s", err))
return errs
} }
// Store the extra configuration for post-processors // Store the extra configuration for post-processors
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment