Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

terraform/exec: Treat TempDir related vars as safe to pass through #78

Merged
merged 2 commits into from
Apr 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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