Closed bjhaid closed 1 year ago
Some additional context: the current behavior (explicitly setting TF_WORKSPACE=""
) breaks tag-selected workspaces using Terraform Cloud such as this:
terraform {
cloud {
organization = "MyOrg"
workspaces {
tags = [
"owner:my-team",
"project:my-project",
]
}
}
}
Normally you'd use terraform workspace select
to select the workspace, but terraform workspace
cannot be used until terraform init
has been run. In order for terraform init
to run you need to either specify TF_WORKSPACE=my-workspace
or you need to populate .terraform/environment
.
The bug here is if TF_WORKSPACE
is defined regardless of value terraform init
skips any checking of .terraform/environment
, including if the value of the env var is ""
.
By removing the TF_WORKSPACE
env var instead of setting it to an empty string allows the automation pattern of using .terraform/environment
to function as intended.
See the official HashiCorp help article Selecting a workspace when running Terraform in automation
@kmoe I fixed the tests can you help re-trigger the builds, thanks!
@kmoe looks like all checks have passed, how do we get this merged and released?
Any chance to get a release out with this change? Thanks!
Setting the environment variable to an empty string confuses the terraform binary as seen below:
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.