boltops-tools / terraspace

Terraspace: The Terraform Framework
https://terraspace.cloud
Apache License 2.0
674 stars 46 forks source link

Add support for Terraform Workspaces #222

Open aidanbr opened 2 years ago

aidanbr commented 2 years ago

Summary

Currently Terraspace doesn't support terraform workspaces unless you change into the Terraspace cache directory and run your commands directly from there.

Motivation

Workspaces are really handy for creating ephemeral environments so it would be nice if Terraspace could support them natively by wrapping around the terraform workspace command.

We can add commands like new and select to the terraform lifecycle hooks (terraform.rb) but commands like list, show and delete will require switching to the cache directory to run them.

Reference-level explanation

Ideally we would be able to run the terraform workspace commands via Terraspace from the root of the project on the current TS_ENV.

So something like this ~

terraspace workspace <stack_name> new <workspace_name>
terraspace workspace <stack_name> select <workspace_name>
terraspace workspace <stack_name> delete <workspace_name>
terraspace workspace <stack_name> list
terraspace workspace <stack_name> show

Drawbacks

Maybe the amount of arguments and ordering of arguments could get quite confusing, but very open to making it simpler if possible.

Unresolved Questions

N/A

ghost commented 2 years ago

Worth mentioning that the TF commands TS uses will already automatically pick up the value of the TF_WORKSPACE environment variable (see the TF docs here) so you can already use workspaces with TS this way.