From e9565028c3afde78a8c6468a404326e133ea9de8 Mon Sep 17 00:00:00 2001 From: Anubhav Mishra Date: Mon, 21 Aug 2017 23:32:02 -0700 Subject: [PATCH 1/3] plan and apply terraform commands error outputs printed after a new line --- terraform/terraform_client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terraform/terraform_client.go b/terraform/terraform_client.go index 9e8eb64b..c728c14a 100644 --- a/terraform/terraform_client.go +++ b/terraform/terraform_client.go @@ -63,7 +63,7 @@ func (c *Client) RunCommandWithVersion(log *logging.SimpleLogger, path string, a out, err := terraformCmd.CombinedOutput() commandStr := strings.Join(terraformCmd.Args, " ") if err != nil { - err := fmt.Errorf("%s: running %q in %q: %s", err, commandStr, path, out) + err := fmt.Errorf("%s: running %q in %q: \n%s", err, commandStr, path, out) log.Debug("error: %s", err) return "", err } From c069ff0f99b228b5f72864a569b904e654d4c2fd Mon Sep 17 00:00:00 2001 From: Anubhav Mishra Date: Wed, 23 Aug 2017 22:42:29 -0700 Subject: [PATCH 2/3] Update terraform_client.go --- terraform/terraform_client.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/terraform/terraform_client.go b/terraform/terraform_client.go index c728c14a..70fa1bf4 100644 --- a/terraform/terraform_client.go +++ b/terraform/terraform_client.go @@ -65,7 +65,7 @@ func (c *Client) RunCommandWithVersion(log *logging.SimpleLogger, path string, a if err != nil { err := fmt.Errorf("%s: running %q in %q: \n%s", err, commandStr, path, out) log.Debug("error: %s", err) - return "", err + return out, err } log.Info("successfully ran %q in %q", commandStr, path) return string(out), nil @@ -79,7 +79,7 @@ func (c *Client) RunInitAndEnv(log *logging.SimpleLogger, path string, env strin // run terraform init output, err := c.RunCommandWithVersion(log, path, append([]string{"init", "-no-color"}, extraInitArgs...), version) if err != nil { - return nil, err + return output, err } outputs = append(outputs, output) @@ -90,7 +90,7 @@ func (c *Client) RunInitAndEnv(log *logging.SimpleLogger, path string, env strin // to create a new environment output, err = c.RunCommandWithVersion(log, path, []string{"env", "new", "-no-color", env}, version) if err != nil { - return nil, err + return output, err } } return append(outputs, output), nil From 02f33c4452cc2ed2ef8fe63cedf30a1f04328ea9 Mon Sep 17 00:00:00 2001 From: Anubhav Mishra Date: Wed, 23 Aug 2017 22:46:41 -0700 Subject: [PATCH 3/3] returning error outputs as well --- terraform/terraform_client.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/terraform/terraform_client.go b/terraform/terraform_client.go index 70fa1bf4..beade022 100644 --- a/terraform/terraform_client.go +++ b/terraform/terraform_client.go @@ -65,7 +65,7 @@ func (c *Client) RunCommandWithVersion(log *logging.SimpleLogger, path string, a if err != nil { err := fmt.Errorf("%s: running %q in %q: \n%s", err, commandStr, path, out) log.Debug("error: %s", err) - return out, err + return string(out), err } log.Info("successfully ran %q in %q", commandStr, path) return string(out), nil @@ -78,20 +78,21 @@ func (c *Client) RunInitAndEnv(log *logging.SimpleLogger, path string, env strin var outputs []string // run terraform init output, err := c.RunCommandWithVersion(log, path, append([]string{"init", "-no-color"}, extraInitArgs...), version) + outputs = append(outputs, output) if err != nil { - return output, err + return outputs, err } - outputs = append(outputs, output) // run terraform env new and select output, err = c.RunCommandWithVersion(log, path, []string{"env", "select", "-no-color", env}, version) + outputs = append(outputs, output) if err != nil { // if terraform env select fails we will run terraform env new // to create a new environment output, err = c.RunCommandWithVersion(log, path, []string{"env", "new", "-no-color", env}, version) if err != nil { - return output, err + return outputs, err } } - return append(outputs, output), nil + return outputs, nil }