Json vs HCL2 parity refactor (#9301)

* refactor so that json and hcl2 templates are both prepared in the same place in the build call, to make code easier to reason about. Remove overly verbose error output which isn't useful in vast majority of cases

* fix tests

* check err msg

* hcl2template.PackerConfig.GetBuilds: raise a diagnostic in case the packer core build perpare call errors

Co-authored-by: Adrien Delorme <[email protected]>
This commit is contained in:
Megan Marsh
2020-05-28 10:43:58 +02:00
committed by GitHub
co-authored by Adrien Delorme
parent d3859cf592
commit 3dc4ba2d68
5 changed files with 44 additions and 28 deletions
-25
View File
@@ -188,31 +188,6 @@ func (c *BuildCommand) RunContext(buildCtx context.Context, cla *BuildArgs) int
log.Printf("Force build: %v", cla.Force)
log.Printf("On error: %v", cla.OnError)
// Set the debug and force mode and prepare all the builds
// This is only affects json templates, because HCL2
// templates have already been prepared in GetBuilds() above.
for i := range builds {
b := builds[i]
log.Printf("Preparing build: %s", b.Name())
b.SetDebug(cla.Debug)
b.SetForce(cla.Force)
b.SetOnError(cla.OnError)
warnings, err := b.Prepare()
if err != nil {
c.Ui.Error(err.Error())
return 1
}
if len(warnings) > 0 {
ui := buildUis[b]
ui.Say(fmt.Sprintf("Warnings for build '%s':\n", b.Name()))
for _, warning := range warnings {
ui.Say(fmt.Sprintf("* %s", warning))
}
ui.Say("")
}
}
// Run all the builds in parallel and wait for them to complete
var wg sync.WaitGroup
var artifacts = struct {