Skip to content

Commit

Permalink
Add better error if plan upload fails
Browse files Browse the repository at this point in the history
- Issue:
  #165
  • Loading branch information
ljfranklin committed Nov 7, 2021
1 parent 2e64e3e commit 0ccd897
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/terraform-resource/terraform/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,8 @@ func (c *client) SavePlanToBackend(planEnvName string) error {
}
c.model.Source = tmpDir

logFile, err := os.OpenFile(path.Join(os.TempDir(), "tf-plan.log"), os.O_RDWR|os.O_CREATE, 0600)
logPath := path.Join(os.TempDir(), "tf-plan.log")
logFile, err := os.OpenFile(logPath, os.O_RDWR|os.O_CREATE, 0600)
if err != nil {
return err
}
Expand All @@ -770,24 +771,27 @@ func (c *client) SavePlanToBackend(planEnvName string) error {
c.logWriter = origLogger
}()

// The /tmp/tf-plan.log file can contain credentials, so we tell the user to
// SSH into the container to view it rather than printing logs directly to the build logs.
errPrefix := "Failed to upload plan file to TF backend. Use `fly intercept` to SSH into this container and view %s for more logs. Error: %s"
err = c.writePlanProviderConfig(tmpDir, planContents, planContentsJSON)
if err != nil {
return err
return fmt.Errorf(errPrefix, logPath, err)
}

err = c.InitWithBackend()
if err != nil {
return err
return fmt.Errorf(errPrefix, logPath, err)
}

err = c.WorkspaceNewIfNotExists(planEnvName)
if err != nil {
return err
return fmt.Errorf(errPrefix, logPath, err)
}

err = c.Apply()
if err != nil {
return err
return fmt.Errorf(errPrefix, logPath, err)
}

return nil
Expand Down

0 comments on commit 0ccd897

Please sign in to comment.