github.com/jpreese/tflint@v0.19.2-0.20200908152133-b01686250fb6/docs/rules/terraform_workspace_remote.md (about)

     1  # terraform_workspace_remote
     2  
     3  `terraform.workspace` should not be used with a "remote" backend with remote execution. 
     4  
     5  If remote operations are [disabled](https://www.terraform.io/docs/cloud/run/index.html#disabling-remote-operations) for your workspace, you can safely disable this rule:
     6  
     7  ```hcl
     8  rule "terraform_workspace_remote" {
     9    enabled = false
    10  }
    11  ```
    12  
    13  ## Example
    14  
    15  ```hcl
    16  terraform {
    17    backend "remote" {
    18      # ...
    19    }
    20  }
    21  
    22  resource "aws_instance" "a" {
    23    tags = {
    24      workspace = terraform.workspace
    25    }
    26  }
    27  ```
    28  
    29  ```
    30  $ tflint
    31  1 issue(s) found:
    32  
    33  Warning: terraform.workspace should not be used with a 'remote' backend (terraform_workspace_remote)
    34  
    35    on example.tf line 8:
    36     8:   tags = {
    37     9:     workspace = terraform.workspace
    38    10:   }
    39  
    40  Reference: https://github.com/terraform-linters/tflint/blob/v0.15.5/docs/rules/terraform_workspace_remote.md
    41  ```
    42  
    43  ## Why
    44  
    45  Terraform configuration may include the name of the [current workspace](https://www.terraform.io/docs/state/workspaces.html#current-workspace-interpolation) using the `${terraform.workspace}` interpolation sequence. However, when Terraform Cloud workspaces are executing Terraform runs remotely, the Terraform CLI always uses the `default` workspace.
    46  
    47  The [remote](https://www.terraform.io/docs/backends/types/remote.html) 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.
    48  
    49  For more information, see the [`remote` backend workspaces documentation](https://www.terraform.io/docs/backends/types/remote.html#workspaces).
    50  
    51  ## How To Fix
    52  
    53  Consider adding a variable to your configuration and setting it in each cloud workspace:
    54  
    55  ```tf
    56  variable "workspace" {
    57    type        = string
    58    description = "The workspace name" 
    59  }
    60  ```
    61  
    62  You can also name the variable based on what the workspace suffix represents in your configuration (e.g. environment).