Skip to content

Commit

Permalink
Prevent unintended usage of TF_WORKSPACE
Browse files Browse the repository at this point in the history
  • Loading branch information
paultyng committed Sep 4, 2020
1 parent 01a7e95 commit 0099850
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 5 additions & 0 deletions tfexec/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const (
logPathEnvVar = "TF_LOG_PATH"
reattachEnvVar = "TF_REATTACH_PROVIDERS"
appendUserAgentEnvVar = "TF_APPEND_USER_AGENT"
workspaceEnvVar = "TF_WORKSPACE"

varEnvVarPrefix = "TF_VAR_"
)
Expand All @@ -33,6 +34,7 @@ var prohibitedEnvVars = []string{
logEnvVar,
reattachEnvVar,
appendUserAgentEnvVar,
workspaceEnvVar,
}

func envMap(environ []string) map[string]string {
Expand Down Expand Up @@ -105,6 +107,9 @@ func (tf *Terraform) buildEnv(mergeEnv map[string]string) []string {
// constant automation override env vars
env[automationEnvVar] = "1"

// force usage of workspace methods for switching
env[workspaceEnvVar] = ""

return envSlice(env)
}

Expand Down
7 changes: 4 additions & 3 deletions tfexec/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ func TestMergeUserAgent(t *testing.T) {

func defaultEnv() []string {
return []string{
"CHECKPOINT_DISABLE=",
"TF_APPEND_USER_AGENT=HashiCorp-terraform-exec/" + version.ModuleVersion(),
"TF_LOG=",
"TF_LOG_PATH=",
"TF_IN_AUTOMATION=1",
"CHECKPOINT_DISABLE=",
"TF_LOG_PATH=",
"TF_LOG=",
"TF_WORKSPACE=",
}
}

Expand Down

0 comments on commit 0099850

Please sign in to comment.