Skip to content

Commit

Permalink
fix loggin in tf.output
Browse files Browse the repository at this point in the history
Signed-off-by: Chanwit Kaewkasi <chanwit@gmail.com>
  • Loading branch information
chanwit committed Jun 6, 2023
1 parent 8ae59eb commit 28282bc
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion runner/server_outputs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package runner
import (
"context"
"fmt"
"io"
"reflect"

"github.com/hashicorp/terraform-exec/tfexec"
infrav1 "github.com/weaveworks/tf-controller/api/v1alpha2"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand All @@ -13,6 +15,18 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
)

func (r *TerraformRunnerServer) tfOutput(ctx context.Context, opts ...tfexec.OutputOption) (map[string]tfexec.OutputMeta, error) {
log := ctrl.LoggerFrom(ctx, "instance-id", r.InstanceID).WithName(loggerName)

// This is the only place where we disable the logger
r.tf.SetStdout(io.Discard)
r.tf.SetStderr(io.Discard)

defer r.initLogger(log)

return r.tf.Output(ctx, opts...)
}

func (r *TerraformRunnerServer) Output(ctx context.Context, req *OutputRequest) (*OutputReply, error) {
log := ctrl.LoggerFrom(ctx, "instance-id", r.InstanceID).WithName(loggerName)
log.Info("creating outputs")
Expand All @@ -22,7 +36,7 @@ func (r *TerraformRunnerServer) Output(ctx context.Context, req *OutputRequest)
return nil, err
}

outputs, err := r.tf.Output(ctx)
outputs, err := r.tfOutput(ctx)
if err != nil {
log.Error(err, "unable to get outputs")
return nil, err
Expand Down

0 comments on commit 28282bc

Please # to comment.