diff --git a/builder/cloudstack/step_configure_networking.go b/builder/cloudstack/step_configure_networking.go index b7161f281..48a3742ab 100644 --- a/builder/cloudstack/step_configure_networking.go +++ b/builder/cloudstack/step_configure_networking.go @@ -47,7 +47,9 @@ func (s *stepSetupNetworking) Run(state multistep.StateBag) multistep.StepAction // Retrieve the instance ID from the previously saved state. instanceID, ok := state.Get("instance_id").(string) if !ok || instanceID == "" { - state.Put("error", fmt.Errorf("Could not retrieve instance_id from state!")) + err := fmt.Errorf("Could not retrieve instance_id from state!") + state.Put("error", err) + ui.Error(err.Error()) return multistep.ActionHalt } @@ -56,7 +58,9 @@ func (s *stepSetupNetworking) Run(state multistep.StateBag) multistep.StepAction cloudstack.WithProject(config.Project), ) if err != nil { - state.Put("error", fmt.Errorf("Failed to retrieve the network object: %s", err)) + err := fmt.Errorf("Failed to retrieve the network object: %s", err) + state.Put("error", err) + ui.Error(err.Error()) return multistep.ActionHalt } @@ -79,7 +83,9 @@ func (s *stepSetupNetworking) Run(state multistep.StateBag) multistep.StepAction // Associate a new public IP address. ipAddr, err := client.Address.AssociateIpAddress(p) if err != nil { - state.Put("error", fmt.Errorf("Failed to associate public IP address: %s", err)) + err := fmt.Errorf("Failed to associate public IP address: %s", err) + state.Put("error", err) + ui.Error(err.Error()) return multistep.ActionHalt } @@ -107,7 +113,10 @@ func (s *stepSetupNetworking) Run(state multistep.StateBag) multistep.StepAction // Create the port forward. forward, err := client.Firewall.CreatePortForwardingRule(p) if err != nil { - ui.Error(fmt.Sprintf("Failed to create port forward: %s", err)) + err := fmt.Errorf("Failed to create port forward: %s", err) + state.Put("error", err) + ui.Error(err.Error()) + return multistep.ActionHalt } // Store the port forward ID. @@ -117,7 +126,9 @@ func (s *stepSetupNetworking) Run(state multistep.StateBag) multistep.StepAction ui.Message("Creating network ACL rule...") if network.Aclid == "" { - state.Put("error", fmt.Errorf("Failed to configure the firewall: no ACL connected to the VPC network")) + err := fmt.Errorf("Failed to configure the firewall: no ACL connected to the VPC network") + state.Put("error", err) + ui.Error(err.Error()) return multistep.ActionHalt } @@ -135,7 +146,9 @@ func (s *stepSetupNetworking) Run(state multistep.StateBag) multistep.StepAction // Create the network ACL rule. aclRule, err := client.NetworkACL.CreateNetworkACL(p) if err != nil { - state.Put("error", fmt.Errorf("Failed to create network ACL rule: %s", err)) + err := fmt.Errorf("Failed to create network ACL rule: %s", err) + state.Put("error", err) + ui.Error(err.Error()) return multistep.ActionHalt } @@ -154,7 +167,9 @@ func (s *stepSetupNetworking) Run(state multistep.StateBag) multistep.StepAction fwRule, err := client.Firewall.CreateFirewallRule(p) if err != nil { - state.Put("error", fmt.Errorf("Failed to create firewall rule: %s", err)) + err := fmt.Errorf("Failed to create firewall rule: %s", err) + state.Put("error", err) + ui.Error(err.Error()) return multistep.ActionHalt } diff --git a/builder/cloudstack/step_create_instance.go b/builder/cloudstack/step_create_instance.go index 1693b654f..3b624de3c 100644 --- a/builder/cloudstack/step_create_instance.go +++ b/builder/cloudstack/step_create_instance.go @@ -62,7 +62,9 @@ func (s *stepCreateInstance) Run(state multistep.StateBag) multistep.StepAction // Retrieve the zone object. zone, _, err := client.Zone.GetZoneByID(config.Zone) if err != nil { + err := fmt.Errorf("Failed to get zone %s by ID: %s", config.Zone, err) state.Put("error", err) + ui.Error(err.Error()) return multistep.ActionHalt } @@ -80,7 +82,9 @@ func (s *stepCreateInstance) Run(state multistep.StateBag) multistep.StepAction httpPort := state.Get("http_port").(uint) httpIP, err := hostIP() if err != nil { + err := fmt.Errorf("Failed to determine host IP: %s", err) state.Put("error", err) + ui.Error(err.Error()) return multistep.ActionHalt } common.SetHTTPIP(httpIP) @@ -93,6 +97,7 @@ func (s *stepCreateInstance) Run(state multistep.StateBag) multistep.StepAction ud, err := s.generateUserData(config.UserData, config.HTTPGetOnly) if err != nil { state.Put("error", err) + ui.Error(err.Error()) return multistep.ActionHalt } @@ -102,7 +107,9 @@ func (s *stepCreateInstance) Run(state multistep.StateBag) multistep.StepAction // Create the new instance. instance, err := client.VirtualMachine.DeployVirtualMachine(p) if err != nil { - state.Put("error", fmt.Errorf("Error creating new instance %s: %s", config.InstanceName, err)) + err := fmt.Errorf("Error creating new instance %s: %s", config.InstanceName, err) + state.Put("error", err) + ui.Error(err.Error()) return multistep.ActionHalt } diff --git a/builder/cloudstack/step_create_template.go b/builder/cloudstack/step_create_template.go index 12f851802..18d6c1fb0 100644 --- a/builder/cloudstack/step_create_template.go +++ b/builder/cloudstack/step_create_template.go @@ -21,7 +21,9 @@ func (s *stepCreateTemplate) Run(state multistep.StateBag) multistep.StepAction // Retrieve the instance ID from the previously saved state. instanceID, ok := state.Get("instance_id").(string) if !ok || instanceID == "" { - state.Put("error", fmt.Errorf("Could not retrieve instance_id from state!")) + err := fmt.Errorf("Could not retrieve instance_id from state!") + state.Put("error", err) + ui.Error(err.Error()) return multistep.ActionHalt } @@ -51,6 +53,7 @@ func (s *stepCreateTemplate) Run(state multistep.StateBag) multistep.StepAction volumeID, err := getRootVolumeID(client, instanceID) if err != nil { state.Put("error", err) + ui.Error(err.Error()) return multistep.ActionHalt } @@ -60,7 +63,9 @@ func (s *stepCreateTemplate) Run(state multistep.StateBag) multistep.StepAction ui.Message("Creating the new template...") template, err := client.Template.CreateTemplate(p) if err != nil { - state.Put("error", fmt.Errorf("Error creating the new template %s: %s", config.TemplateName, err)) + err := fmt.Errorf("Error creating the new template %s: %s", config.TemplateName, err) + state.Put("error", err) + ui.Error(err.Error()) return multistep.ActionHalt } diff --git a/builder/cloudstack/step_prepare_config.go b/builder/cloudstack/step_prepare_config.go index b1390b9da..af28a76a8 100644 --- a/builder/cloudstack/step_prepare_config.go +++ b/builder/cloudstack/step_prepare_config.go @@ -134,6 +134,7 @@ func (s *stepPrepareConfig) Run(state multistep.StateBag) multistep.StepAction { // nil interface. if errs != nil && len(errs.Errors) > 0 { state.Put("error", errs) + ui.Error(errs.Error()) return multistep.ActionHalt } diff --git a/builder/cloudstack/step_shutdown_instance.go b/builder/cloudstack/step_shutdown_instance.go index 638b0e58b..b090a5836 100644 --- a/builder/cloudstack/step_shutdown_instance.go +++ b/builder/cloudstack/step_shutdown_instance.go @@ -30,7 +30,9 @@ func (s *stepShutdownInstance) Run(state multistep.StateBag) multistep.StepActio // Shutdown the virtual machine. _, err := client.VirtualMachine.StopVirtualMachine(p) if err != nil { - state.Put("error", fmt.Errorf("Error shutting down instance %s: %s", config.InstanceName, err)) + err := fmt.Errorf("Error shutting down instance %s: %s", config.InstanceName, err) + state.Put("error", err) + ui.Error(err.Error()) return multistep.ActionHalt }