cloudposse / atmos

👽 Terraform Orchestration Tool for DevOps. Keep environment configuration DRY with hierarchical imports of configurations, inheritance, and WAY more. Native support for Terraform and Helmfile.
https://atmos.tools
Apache License 2.0
607 stars 83 forks source link

`atmos terraform workspace` does not set workspace #574

Closed Nuru closed 1 month ago

Nuru commented 1 month ago

Describe the Bug

Prior to Atmos v1.55.0 and #515, atmos terraform init and atmos terraform workspace would select the correct Terraform workspace for the component and stack, allowing further terraform commands to work correctly without needing atmos to wrap them.

Now, atmos terraform init leaves the selected workspace as-is and atmos terraform workspace does nothing. This has lead me to come close to applying changes to the wrong environment and I fear that soon I will not catch onto the situation and make the bad changes by mistake.

Expected Behavior

atmos terraform workspace by definition should select the Terraform workspace using terraform workspace select, leaving the workspace selected for future terraform commands (without Atmos).

I would also like atmos terraform init to resume its previous behavior of selected the workspace, so that I do not have to explicitly run atmos terraform workspace to select the workspace, as was the case before v1.55.

Steps to Reproduce

Output will show that the default workspace is still selected.

Screenshots

No response

Environment

No response

Additional Context

The justification for the change in #515 was that it was more efficient than running 2 commands, one to switch to the workspace and another to create it if it did not exist. Since Terraform 1.4, terraform workspace select has an -or-create option allowing you to restore the old behavior with a single command:

terraform workspace select -or-create <workspace>

However, if you want to continue to support older versions of Terraform, you can simply revert the change in #515. IMHO, the lack of persistence of workspace selection is not worth the minimal (if any) efficiency improvement. The create command is only run rarely, and under the hood Terraform must be running the same logic anyway.