post-processor/vagrant: fix output ConfigTemplate validation [GH-324]
-apply same output validation steps found in builder specific Configure functions
This commit is contained in:
parent
251abc3496
commit
0e3365782a
|
@ -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{
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
||||||
// 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 {
|
||||||
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
|
||||||
|
|
Loading…
Reference in New Issue