i’ve been using terraform cloud and was trying to achieve some configuration diffs between workspaces using the below example
resource "aws_instance" "example" {
count = "${terraform.workspace == "default" ? 5 : 1}"
# ... other arguments
}
(https://www.terraform.io/docs/state/workspaces.html#current-workspace-interpolation)
but when i run it in the terraform cloud the result of the ${terraforn.workspace} is “default” and not the actual workspace name
is that a bug? any other method i should check for achieving a similar result?
2 Likes
I am having the same issue.
Hi!
Regrettably, Terraform CLI workspaces are somewhat different from Terraform Cloud workspaces; this is something we’re aware of and looking to correct a bit in the future, as it is a bit confusing. The default
you see there is referring to the former and not the workspace in Terraform Cloud.
In the meantime, a similar result can be achieved by using Terraform Cloud workspaces exclusively and variables set on the workspace. Your count
there could be set on different workspaces (split by the type of environment e.g. production, staging, whatever) on the same variable with different values depending on the workspace. See https://www.terraform.io/docs/cloud/workspaces/variables.html for more.
In essence, at the current time I’d generally say if you’re using Terraform Cloud you’ll want to use Cloud workspaces exclusively and not use CLI workspaces at all, though as I said, we hope the experience there is more streamlined in the CLI in the future.
1 Like