diff --git a/tfexec/cmd.go b/tfexec/cmd.go index c91be139..7473b66c 100644 --- a/tfexec/cmd.go +++ b/tfexec/cmd.go @@ -22,6 +22,7 @@ const ( logPathEnvVar = "TF_LOG_PATH" reattachEnvVar = "TF_REATTACH_PROVIDERS" appendUserAgentEnvVar = "TF_APPEND_USER_AGENT" + workspaceEnvVar = "TF_WORKSPACE" varEnvVarPrefix = "TF_VAR_" ) @@ -33,6 +34,7 @@ var prohibitedEnvVars = []string{ logEnvVar, reattachEnvVar, appendUserAgentEnvVar, + workspaceEnvVar, } func envMap(environ []string) map[string]string { @@ -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) } diff --git a/tfexec/cmd_test.go b/tfexec/cmd_test.go index 00424e9d..3f283208 100644 --- a/tfexec/cmd_test.go +++ b/tfexec/cmd_test.go @@ -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=", } }