Skip to content

Commit

Permalink
feat: allow using a new process group for the terraform cli child pro…
Browse files Browse the repository at this point in the history
…cess
  • Loading branch information
kristina-solovyova committed May 1, 2024
1 parent 259b9e9 commit 998b5f0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tfexec/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"os"
"os/exec"
"strings"
"syscall"

"github.com/hashicorp/terraform-exec/internal/version"
)
Expand Down Expand Up @@ -187,6 +188,12 @@ func (tf *Terraform) buildTerraformCmd(ctx context.Context, mergeEnv map[string]

cmd.Env = tf.buildEnv(mergeEnv)
cmd.Dir = tf.workingDir
// Create a new process group for the command
if tf.useSepProcessGroup {
cmd.SysProcAttr = &syscall.SysProcAttr{
Setpgid: true,
}
}

tf.logger.Printf("[INFO] running Terraform command: %s", cmd.String())

Expand Down
8 changes: 8 additions & 0 deletions tfexec/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type Terraform struct {
appendUserAgent string
disablePluginTLS bool
skipProviderVerify bool
useSepProcessGroup bool
env map[string]string

stdout io.Writer
Expand Down Expand Up @@ -136,6 +137,13 @@ func (tf *Terraform) SetStderr(w io.Writer) {
tf.stderr = w
}

// SetUseSeparateProcessGroup specifies whether to use a separate process group
// when running Terraform Cmd.
func (tf *Terraform) SetUseSeparateProcessGroup(use bool) error {
tf.useSepProcessGroup = use
return nil
}

// SetLog sets the TF_LOG environment variable for Terraform CLI execution.
// This must be combined with a call to SetLogPath to take effect.
//
Expand Down

0 comments on commit 998b5f0

Please sign in to comment.