Make sure we always print and return any errors

This commit is contained in:
Sander van Harmelen
2017-07-06 23:31:13 +02:00
parent 4313f98061
commit c4ef9bcd3f
6 changed files with 27 additions and 26 deletions
+9 -8
View File
@@ -7,6 +7,7 @@ import (
"net"
"strings"
"github.com/hashicorp/packer/common"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/template/interpolate"
"github.com/mitchellh/multistep"
@@ -61,7 +62,7 @@ func (s *stepCreateInstance) Run(state multistep.StateBag) multistep.StepAction
// Retrieve the zone object.
zone, _, err := client.Zone.GetZoneByID(config.Zone)
if err != nil {
ui.Error(err.Error())
state.Put("error", err)
return multistep.ActionHalt
}
@@ -77,27 +78,27 @@ func (s *stepCreateInstance) Run(state multistep.StateBag) multistep.StepAction
if config.UserData != "" {
httpPort := state.Get("http_port").(uint)
hostIp, err := hostIP()
httpIP, err := hostIP()
if err != nil {
ui.Error(err.Error())
state.Put("error", err)
return multistep.ActionHalt
}
common.SetHTTPIP(httpIP)
s.Ctx.Data = &userDataTemplateData{
hostIp,
httpIP,
httpPort,
}
renderedUserData, err := interpolate.Render(config.UserData, &s.Ctx)
if err != nil {
err := fmt.Errorf("Error rendering user_data: %s", err)
ui.Error(err.Error())
state.Put("error", fmt.Errorf("Error rendering user_data: %s", err))
return multistep.ActionHalt
}
ud, err := getUserData(renderedUserData, config.HTTPGetOnly)
if err != nil {
ui.Error(err.Error())
state.Put("error", err)
return multistep.ActionHalt
}
@@ -107,7 +108,7 @@ func (s *stepCreateInstance) Run(state multistep.StateBag) multistep.StepAction
// Create the new instance.
instance, err := client.VirtualMachine.DeployVirtualMachine(p)
if err != nil {
ui.Error(fmt.Sprintf("Error creating new instance %s: %s", config.InstanceName, err))
state.Put("error", fmt.Errorf("Error creating new instance %s: %s", config.InstanceName, err))
return multistep.ActionHalt
}