Skip to main content

tharsis_variable

Defines and manages a namespace variable.

Example Usage​

resource "tharsis_variable" "region" {
namespace_path = "my-group/my-workspace"
category = "terraform"
key = "region"
value = "us-east-1"
}

resource "tharsis_variable" "log_level" {
namespace_path = "my-group"
category = "environment"
key = "TF_LOG"
value = "INFO"
}

Behavior​

  • A variable is set on a group or a workspace, identified by namespace_path (for example my-group or my-group/my-workspace).
  • A variable with the terraform category is an input variable for the module that the workspace runs, so its key must match a variable declared by the module.
  • A variable with the environment category is an environment variable set while Terraform executes.
  • A variable set on a group is inherited by its child groups and workspaces. Creating a variable with the same key and category in a child namespace overrides the inherited value.
  • When the same key and category are set at several levels, a workspace variable takes precedence over its group's variable, and a child group's variable takes precedence over its parent group's variable.

Restricted environment variable keys​

Tharsis rejects some environment variable keys, including TF_VAR_*, TF_CLI_ARGS, TF_CLI_ARGS_*, TF_INPUT, TF_IN_AUTOMATION, TF_LOG_PATH, and TF_WORKSPACE. To set a Terraform input variable, use the terraform category instead of TF_VAR_*.

Schema​

Required​

  • category (String) Whether this variable is a Terraform or an environment variable.
  • key (String) This variable's key (within its namespace).
  • namespace_path (String) The path to this variable's namespace.
  • value (String) This variable's value.

Read-Only​

  • id (String) String identifier of the namespace variable.

Import​

Import is supported using the following syntax:

In Terraform v1.5.0 and later, the import block can be used with the id attribute, for example:

# A namespace variable can be imported by its TRN, which is "trn:variable:"
# followed by the namespace path, the category ("terraform" or "environment"),
# and the key.
import {
to = tharsis_variable.region
id = "trn:variable:my-group/my-workspace/terraform/region"
}

# A variable set on a group rather than a workspace uses the group's path.
import {
to = tharsis_variable.log_level
id = "trn:variable:my-group/environment/TF_LOG"
}

# The variable's ID also works as the id, shown by the "id" attribute.