terraform.workspace
should not be used with a "remote" backend with remote execution.
If remote operations are disabled for your workspace, you can safely disable this rule:
rule "terraform_workspace_remote" {
enabled = false
}
terraform {
backend "remote" {
# ...
}
}
resource "aws_instance" "a" {
tags = {
workspace = terraform.workspace
}
}
$ tflint
1 issue(s) found:
Warning: terraform.workspace should not be used with a 'remote' backend (terraform_workspace_remote)
on example.tf line 8:
8: tags = {
9: workspace = terraform.workspace
10: }
Reference: https://github.com/terraform-linters/tflint/blob/v0.15.5/docs/rules/terraform_workspace_remote.md
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.
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).