From 35a87777216d32b824e154f273ed0a2e82ef4289 Mon Sep 17 00:00:00 2001 From: patoarvizu Date: Sun, 20 Feb 2022 11:31:56 -0500 Subject: [PATCH] Log output of Terraform commands --- controllers/terraformstate_controller.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/controllers/terraformstate_controller.go b/controllers/terraformstate_controller.go index 49b0546..95a4094 100644 --- a/controllers/terraformstate_controller.go +++ b/controllers/terraformstate_controller.go @@ -148,22 +148,26 @@ func (r *TerraformStateReconciler) Reconcile(req ctrl.Request) (ctrl.Result, err cmd := exec.Command("/terraform-bin/terraform", "apply", "-auto-approve") cmd.Dir = stateDir - err = cmd.Run() + output, err := cmd.CombinedOutput() + r.Log.Info(string(output)) if err != nil { return ctrl.Result{}, err } cmd = exec.Command("/terraform-bin/terraform", "output", "-json") cmd.Dir = stateDir - var out bytes.Buffer - cmd.Stdout = &out + var stdout bytes.Buffer + cmd.Stdout = &stdout + var stderr bytes.Buffer + cmd.Stderr = &stderr err = cmd.Run() if err != nil { + r.Log.Info(stderr.String()) return ctrl.Result{}, err } var tfOutputs terraformOutputs - err = json.Unmarshal(out.Bytes(), &tfOutputs) + err = json.Unmarshal(stdout.Bytes(), &tfOutputs) if err != nil { return ctrl.Result{}, err }