Audit: `terraform.workspace` used with a `remote` backend with remote executionTF-L0049
Note: If remote operations are disabled for your workspace, you can safely disable this warning.
Terraform configuration may include the name of the current workspace using the ${terraform.workspace}
interpolation sequence.
However, when Terraform Cloud workspaces are executing Terraform runs remotely, the Terraform CLI always uses the default workspace
.
The remote backend is used with Terraform Cloud workspaces. Even if you set a prefix
in the workspaces
block, this value will be ignored during remote runs.
For more information, see the remote backend workspaces documentation.
Example:
terraform {
backend "remote" {
# ...
}
}
resource "aws_instance" "a" {
tags = {
workspace = terraform.workspace
}
}
To fix this, consider adding a variable to your configuration and setting it in each cloud workspace:
variable "workspace" {
type = string
description = "The workspace name"
}
You can also name the variable based on what the workspace suffix represents in your configuration (e.g. environment).