command/validate: Validate configuration
This commit is contained in:
parent
a35feebe70
commit
57725da852
|
@ -64,7 +64,7 @@ func (c Command) Run(env packer.Environment, args []string) int {
|
||||||
// Otherwise, get all the builds
|
// Otherwise, get all the builds
|
||||||
buildNames := tpl.BuildNames()
|
buildNames := tpl.BuildNames()
|
||||||
builds := make([]packer.Build, 0, len(buildNames))
|
builds := make([]packer.Build, 0, len(buildNames))
|
||||||
for i, buildName := range buildNames {
|
for _, buildName := range buildNames {
|
||||||
build, err := tpl.Build(buildName, components)
|
build, err := tpl.Build(buildName, components)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errs = append(errs, fmt.Errorf("Build '%s': %s", buildName, err))
|
errs = append(errs, fmt.Errorf("Build '%s': %s", buildName, err))
|
||||||
|
@ -74,11 +74,24 @@ func (c Command) Run(env packer.Environment, args []string) int {
|
||||||
builds = append(builds, build)
|
builds = append(builds, build)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(mitchellh): validate configuration
|
// Check the configuration of all builds
|
||||||
|
for _, b := range builds {
|
||||||
|
err := b.Prepare()
|
||||||
|
if err != nil {
|
||||||
|
errs = append(errs, fmt.Errorf("Errors validating build '%s'. %s", b.Name(), err))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if len(errs) > 0 {
|
if len(errs) > 0 {
|
||||||
err = &packer.MultiError{errs}
|
env.Ui().Error("Template validation failed. Errors are shown below.\n")
|
||||||
env.Ui().Error(fmt.Sprintf("Template validation failed. %s", err))
|
for i, err := range errs {
|
||||||
|
env.Ui().Error(err.Error())
|
||||||
|
|
||||||
|
if (i+1) < len(errs) {
|
||||||
|
env.Ui().Error("")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue