aws/aws-sam-cli

Feature request: Support workspaces in Terraform

tam116 opened this issue · 3 comments

Currently sam build with the terraform hook use the default workspace. I use workspaces when developing terraform modules to test changes without affecting production infrastructure.

I typically use a pattern where I use the workspace value as the key for selecting value from other map variables. A short example is below.
locals {
Environment = terraform.workspace
log_level = {
"prod" = "INFO"
"dev" = "DEBUG"
}
module "interfolio_uploader_lambda" {
source = "terraform-aws-modules/lambda/aws"
environment_variables = {
"LOG_LEVEL" : local.log_level[local.Environment]
}
... other config ...
}

Proposal

I see a couple of ways to solve this:

  1. Guess the environment by looking at the .terraform/environment file inside the root module directory. It would require that the user has already run terraform init and terraform workspace select/new <environment>
  2. Pass the value of the sam CLI --config-env flag to the terraform hook

Thanks @tam116 for raising this feature request.
This issue is similar to the issue #4439 you raised, and the workaround I can suggest on you is also to use the Terraform environment variable https://developer.hashicorp.com/terraform/cli/config/environment-variables#tf_workspace to customize your workspace. Could you please try this workaround, and let us know if you face any issues.

We will add this request to the task we are planning to work on to allow customizing the Terraform workspace using SAM CLI arguments/options.

I will close this feature request as it is duplicate for issue #4439, Please keep an eye on the other issue for updates.

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.