
- Variable sets let you define a named collection of variables once and apply them to one or more workspaces or projects.
- They reduce duplication, simplify credential rotation, and centralize configuration for shared settings (e.g., cloud credentials, database defaults, instance sizes, audit settings).
- Production cloud: AWS credentials (
secret id,secret access key,region). - Database settings:
read/writecapacity defaults. - VM sizing: instance types for QA, Test, and Prod.
- Audit configs: logging path and rotation settings applied org-wide.

Store sensitive credentials using the platform’s sensitive/secret variable options. Avoid putting plaintext secrets in VCS or documentation.
Use narrower scopes for team- or workload-specific settings, and global scope only for truly organization-wide defaults.

- Workspace-specific variables override values from variable sets applied to that workspace.
- Variable set defines:
db_write_capacity = 1db_read_capacity = 1
- The set is applied to three workspaces; all three inherit both values.
- For one workspace (e.g., a reporting app) you set a workspace-specific variable:
db_read_capacity = 10
db_read_capacity = 10, while the other two workspaces continue to use db_read_capacity = 1.
Workspace-specific variables always take precedence over values from variable sets applied to that workspace.
- Priority variable sets: You can mark a variable set as a priority set. Priority sets override values even in more specific scopes (including workspace-specific variables). Use this sparingly for admin-enforced values (e.g., security or compliance defaults). Note: runtime inputs usually override priority sets.
- CLI and environment overrides: Values passed at runtime via CLI flags (
-var,-var-file) or environment variables prefixed withTF_VAR_override workspace and variable set values. These runtime inputs generally have the highest precedence for a run. - Conflicts between variable sets at the same scope: If multiple variable sets at the same scope define the same key, HCP Terraform resolves the conflict by lexical (alphabetical) order of the variable set names — the alphabetically first set wins.

- Centralize shared credentials and settings in variable sets to reduce duplication and simplify rotation.
- Choose scope deliberately: use Global sparingly, Project for team-wide defaults, Workspace for targeted overrides.
- Use priority sets only when you need admin-enforced, non-overridable values.
- Expect runtime CLI and
TF_VAR_environment values to take precedence when running Terraform. - When conflicts arise between sets at the same scope, alphabetical ordering determines which set wins.
- HCP Terraform docs: https://www.hashicorp.com/products/terraform
- Terraform variables: https://www.terraform.io/docs/language/values/variables.html