<#22209 Support for Terraform workspaces with Terr...
# github-notifications
c
#22209 Support for Terraform workspaces with Terraform backend Issue created by d-m Is your feature request related to a problem? Please describe. Terraform provided the ability to segment state for different deployments in workspaces that can be created or selected with
terraform workspace new <name>
and
terraform workspace select <name>
, respectively. Using these would be easier if the TerraformDeploymentTarget accepted a
workspace
parameter and this was used to create or select a workspace. Describe the solution you'd like A
workspace
parameter was set, possibly by environment variable, and used like so:
Copy code
terraform_deployment(
    ...
    workspace="my-workspace",
    ...
)
Describe alternatives you've considered I've tried creating a
shell_command
(#22208) to create the workspace and set it as a dependency to a
terraform_deployment
but I couldn't get it to run. I've also tried using a
run_shell_command
target and running
pants run
. This worked if there was only one
run_shell_command
but didn't if there were multiple, for example a monorepo with multiple terraform projects. Additional context Terraform can sometimes create a new workspace automatically (hashicorp/terraform#21393 (comment), hashicorp/terraform#21393 (comment)), but it is not guaranteed for all backend providers and often returns this error:
Copy code
Initializing the backend...

The currently selected workspace (my-workspace) does not exist.
  This is expected behavior when the selected workspace did not have an
  existing non-empty state. Please enter a number to select a workspace:
  ...
It is more consistent to run
terraform workspace new
to create it. pantsbuild/pants