diff --git a/builder/googlecompute/step_start_tunnel.go b/builder/googlecompute/step_start_tunnel.go index 031fb06be..7536f705c 100644 --- a/builder/googlecompute/step_start_tunnel.go +++ b/builder/googlecompute/step_start_tunnel.go @@ -100,7 +100,10 @@ func (s *StepStartTunnel) createTempGcloudScript(args []string) (string, error) s.IAPConf.IAPHashBang = fmt.Sprintf("#!%s\n", s.IAPConf.IAPHashBang) log.Printf("[INFO] (google): Prepending inline gcloud setup script with %s", s.IAPConf.IAPHashBang) - writer.WriteString(s.IAPConf.IAPHashBang) + err = writer.WriteString(s.IAPConf.IAPHashBang) + if err != nil { + return "", fmt.Errorf("Error preparing inline hashbang: %s", err) + } // authenticate to gcloud _, err = writer.WriteString( @@ -128,7 +131,10 @@ func (s *StepStartTunnel) createTempGcloudScript(args []string) (string, error) // figure out what extension the file should have, and rename it. tempScriptFileName := tf.Name() if s.IAPConf.IAPExt != "" { - os.Rename(tempScriptFileName, fmt.Sprintf("%s%s", tempScriptFileName, s.IAPConf.IAPExt)) + err := os.Rename(tempScriptFileName, fmt.Sprintf("%s%s", tempScriptFileName, s.IAPConf.IAPExt)) + if err != nil { + return "", fmt.Errorf("Error setting the correct temp file extension: %s", err) + } tempScriptFileName = fmt.Sprintf("%s%s", tempScriptFileName, s.IAPConf.IAPExt) } @@ -179,7 +185,6 @@ func (s *StepStartTunnel) Run(ctx context.Context, state multistep.StateBag) mul } defer os.Remove(tempScriptFileName) - // Shell out to gcloud. s.tunnelDriver = NewTunnelDriver() err = retry.Config{ @@ -201,5 +206,4 @@ func (s *StepStartTunnel) Run(ctx context.Context, state multistep.StateBag) mul // Cleanup stops the IAP tunnel and cleans up processes. func (s *StepStartTunnel) Cleanup(state multistep.StateBag) { s.tunnelDriver.StopTunnel() - return } diff --git a/builder/googlecompute/tunnel_driver.go b/builder/googlecompute/tunnel_driver.go index b07bc2ef2..78d9be634 100644 --- a/builder/googlecompute/tunnel_driver.go +++ b/builder/googlecompute/tunnel_driver.go @@ -36,7 +36,6 @@ func (t *TunnelDriverLinux) StartTunnel(cancelCtx context.Context, tempScriptFil if err != nil { err := fmt.Errorf("Error calling gcloud sdk to launch IAP tunnel: %s", err) - cmd.Process.Kill() return err } // Wait for tunnel to launch and gather response. TODO: do this without @@ -53,9 +52,8 @@ func (t *TunnelDriverLinux) StartTunnel(cancelCtx context.Context, tempScriptFil serr := stderr.String() log.Println(serr) if strings.Contains(serr, "ERROR") { - cmd.Process.Kill() errIdx := strings.Index(serr, "ERROR:") - return fmt.Errorf("ERROR: %s", serr[errIdx+7:len(serr)]) + return fmt.Errorf("ERROR: %s", serr[errIdx+7:]) } // Store successful command on step so we can access it to cancel it // later. @@ -72,7 +70,10 @@ func (t *TunnelDriverLinux) StopTunnel() { // daemon child. We create the group ID with the syscall.SysProcAttr // call inside the retry loop above, and then store that ID on the // command so we can destroy it here. - syscall.Kill(-t.cmd.Process.Pid, syscall.SIGKILL) + err := syscall.Kill(-t.cmd.Process.Pid, syscall.SIGKILL) + if err != nil { + log.Printf("Issue stopping IAP tunnel: %s", err) + } } else { log.Printf("Couldn't find IAP tunnel process to kill. Continuing.") }