From a4078be65fbd94390a9d4d04c1165bda6866995c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=80b=C3=A9j=C3=ADd=C3=A9=20=C3=80yod=C3=A9l=C3=A9?= Date: Tue, 2 May 2023 16:47:57 -0700 Subject: [PATCH] remove workspace env var and not set it to an empty string. Setting the environment variable to an empty string confuses the terraform binary as seen below: ``` TF_WORKSPACE= terraform init -no-color -input=false -get=false -upgrade=false -backend=false Error: Terraform Cloud returned an unexpected error invalid value for workspace ``` With this patch the `TF_WORKSPACE` will not exist and avoids the above problem. I have tested this locally with terraform 1.4.5 and it works. --- tfexec/cmd.go | 2 +- tfexec/cmd_test.go | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/tfexec/cmd.go b/tfexec/cmd.go index 083dc4d5..5e160324 100644 --- a/tfexec/cmd.go +++ b/tfexec/cmd.go @@ -169,7 +169,7 @@ func (tf *Terraform) buildEnv(mergeEnv map[string]string) []string { env[automationEnvVar] = "1" // force usage of workspace methods for switching - env[workspaceEnvVar] = "" + delete(env, workspaceEnvVar) if tf.disablePluginTLS { env[disablePluginTLSEnvVar] = "1" diff --git a/tfexec/cmd_test.go b/tfexec/cmd_test.go index 5aa6fae6..c86dae30 100644 --- a/tfexec/cmd_test.go +++ b/tfexec/cmd_test.go @@ -46,7 +46,6 @@ func defaultEnv() []string { "TF_LOG_CORE=", "TF_LOG_PATH=", "TF_LOG_PROVIDER=", - "TF_WORKSPACE=", } }