Variable Sets and Run Triggers
Workspaces often share settings and depend on each other's outputs. This lesson covers variable sets for shared variables, and run triggers and output sharing for dependent workspaces.
Learning outcomes
After completing this lesson, you will be able to:
- Explain variable set scopes and precedence.
- Describe run triggers and ways to share outputs between workspaces.
Variable sets
A variable set is a named group of Terraform and environment variables that can be applied to many workspaces at once. Typical contents are shared cloud credentials, a default region or common tags. A variable set is scoped to the whole organisation (global), to selected projects or to selected workspaces. Changing a value in the set changes it for every workspace that uses it, which avoids copying credentials into dozens of workspaces.
When the same variable is defined in several places, the most specific definition wins: workspace-specific variables override variable sets, and among sets, workspace-scoped sets override project-scoped ones, which override global ones. In CLI-driven runs, run-specific values from -var, -var-file and local TF_VAR_ variables override workspace variables and variable sets. A set marked as a priority variable set overrides all of these, including workspace and run-specific variables, which lets administrators enforce a value, such as a mandatory tag.
-
Global variable set
Lowest precedence among sets.
-
Project-scoped variable set
Overrides global sets.
-
Workspace-scoped variable set
Overrides project-scoped sets.
-
Workspace-specific variable
Overrides all non-priority sets.
-
Run-specific values in CLI-driven runs
-var, -var-file and local TF_VAR_ values override workspace variables.
-
Priority variable set
Overrides everything, including workspace and run-specific variables.
Which variable value wins?
Run triggers
Infrastructure layers depend on each other: the application uses the network's subnets. A run trigger connects a source workspace to a destination workspace, so that when a run in the source applies successfully, HCP Terraform queues a run in the destination. A destination workspace can have up to 20 source workspaces. Runs queued by triggers follow the destination's own settings, so without auto-apply they still wait for approval.
The following diagram shows a run trigger and how one workspace reads another's outputs.

Run triggers
Sharing outputs between workspaces
The destination reads the source's root outputs in one of two ways. The tfe_outputs data source from the hashicorp/tfe provider reads only outputs, and marks them sensitive. The terraform_remote_state data source with the remote backend reads the outputs but needs access to the full state. The source workspace's remote state sharing setting decides which workspaces may read its state: all workspaces in the organisation, or only selected ones.
data "tfe_outputs" "network" {
organization = "example-org"
workspace = "network-prod"
}
resource "aws_instance" "app" {
subnet_id = data.tfe_outputs.network.values.private_subnet_ids[0]
# ...
}Reading another workspace's outputs
Chaining network and application
When the network team adds a subnet, the application workspace should re-plan so that its load balancer uses the new subnet. The application team should not be able to read the network state's other data.
The decisive requirements are automatic re-planning and limited access.
A run trigger with network-prod as source and app-prod as destination queues an application run after each successful network apply. The application configuration reads the subnet IDs with tfe_outputs, which exposes only outputs, and the network workspace's remote state sharing is limited to app-prod.
A variable is set in a global variable set and as a workspace variable. Which value applies?
Show answer
The workspace variable, unless the variable set is a priority variable set.
Exam Tips
Remember for the exam
- Variable sets scope: global, projects or workspaces.
- Workspace variables override non-priority sets; priority sets override all.
- Run triggers queue a destination run after a source applies; up to 20 sources.
- tfe_outputs reads outputs only; terraform_remote_state needs full state access.