Skip to content

Commit

Permalink
Merge pull request #78 from hashicorp/b-pass-tmp-vars
Browse files Browse the repository at this point in the history
terraform/exec: Treat TempDir related vars as safe to pass through
  • Loading branch information
radeksimko authored Apr 30, 2020
2 parents d051a16 + e807d94 commit c29fd7a
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions internal/terraform/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ import (
"github.com/hashicorp/terraform-ls/logging"
)

// Environment variables to pass through to Terraform
var passthroughEnvVars = []string{
// This allows Terraform to find custom-built providers
"HOME", "USER", "USERPROFILE",
// This allows Terraform to create crash log in the desired temp directory
// os.TempDir would otherwise fall back to C:\Windows on Windows
// which has no write permissions for non-admins
"TMPDIR", "TMP", "TEMP",
}

// cmdCtxFunc allows mocking of Terraform in tests while retaining
// ability to pass context for timeout/cancellation
type cmdCtxFunc func(context.Context, string, ...string) *exec.Cmd
Expand Down Expand Up @@ -100,12 +110,10 @@ func (e *Executor) cmd(args ...string) (*command, error) {
// so we don't need to ask checkpoint for upgrades.
cmd.Env = append(cmd.Env, "CHECKPOINT_DISABLE=1")

// This allows Terraform to find custom-built providers
if v := os.Getenv("HOME"); v != "" {
cmd.Env = append(cmd.Env, "HOME="+v)
}
if v := os.Getenv("USER"); v != "" {
cmd.Env = append(cmd.Env, "USER="+v)
for _, key := range passthroughEnvVars {
if value := os.Getenv(key); value != "" {
cmd.Env = append(cmd.Env, key+"="+value)
}
}

if e.execLogPath != "" {
Expand Down

0 comments on commit c29fd7a

Please sign in to comment.