From c20ef6214396def9772fde31d4257f523be4c071 Mon Sep 17 00:00:00 2001 From: Junfeng Wu Date: Thu, 8 Aug 2024 18:50:07 +0800 Subject: [PATCH] feat: add option to set stdout/err --- pkg/terraform/terraform.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkg/terraform/terraform.go b/pkg/terraform/terraform.go index e45d80e..635a2fd 100644 --- a/pkg/terraform/terraform.go +++ b/pkg/terraform/terraform.go @@ -87,6 +87,9 @@ type ApplyOptions struct { GracefulShutdownPeriod time.Duration LockExpirationDuration time.Duration InitOptions TFInitOptions + + StdOut io.Writer + StdErr io.Writer } func (t *Terraform) ApplyModule(ctx context.Context, moduleOptions ModuleOptions, applyOptions ApplyOptions) error { @@ -121,6 +124,9 @@ type DestroyOptions struct { GracefulShutdownPeriod time.Duration LockExpirationDuration time.Duration InitOptions TFInitOptions + + StdOut io.Writer + StdErr io.Writer } func (t *Terraform) DestroyModule(ctx context.Context, options ModuleOptions, destroyOptions DestroyOptions) error { @@ -348,6 +354,9 @@ func (t *Terraform) terraformInitAndApply(ctx context.Context, workingDir, backe return eris.Wrap(err, "failed to create Terraform exec") } + tf.SetStdout(options.StdOut) + tf.SetStderr(options.StdErr) + err = tfInit(ctx, tf, backendPath, options.InitOptions) if err != nil { return eris.Wrap(err, "failed to init terraform") @@ -378,6 +387,9 @@ func (t *Terraform) terraformInitAndDestroy(ctx context.Context, workingDir, bac return eris.Wrap(err, "failed to create Terraform exec") } + tf.SetStdout(options.StdOut) + tf.SetStderr(options.StdErr) + err = tfInit(ctx, tf, backendPath, options.InitOptions) if err != nil { return eris.Wrap(err, "failed to init terraform")