Skip to content

Commit 4d2a2a1

Browse files
committed
TF-9289 document priority varsets
1 parent 54af4a4 commit 4d2a2a1

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

website/docs/cloud-docs/api-docs/variable-sets.mdx

+12-4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Properties without a default value are required.
2727
| `data.name` | string | | The name of the variable set. |
2828
| `data.description` | string | `""` | Text displayed in the UI to contextualize the variable set and its purpose. |
2929
| `data.global` | boolean | `false` | When true, Terraform Cloud automatically applies the variable set to all current and future workspaces in the organization. |
30+
| `data.priority` | boolean | `false` | When true, the variables in the set override any other variable values set in a more specific scope including values set on the command line. |
3031
| `data.relationships.workspaces` | array | \`[]` | Array of references to workspaces that the variable set should be assigned to. |
3132
| `data.relationships.projects` | array | \`[]` | Array of references to projects that the variable set should be assigned to. |
3233
| `data.relationships.vars` | array | \`[]` | Array of complete variable definitions that comprise the variable set. |
@@ -48,7 +49,8 @@ Terraform Cloud does not allow different global variable sets to contain conflic
4849
"attributes": {
4950
"name": "MyVarset",
5051
"description": "Full of vars and such for mass reuse",
51-
"global": false
52+
"global": false,
53+
"priority": false,
5254
},
5355
"relationships": {
5456
"workspaces": {
@@ -97,7 +99,8 @@ curl \
9799
"attributes": {
98100
"name": "MyVarset",
99101
"description": "Full of vars and such for mass reuse",
100-
"global": false
102+
"global": false,
103+
"priority": false,
101104
},
102105
"relationships": {
103106
"workspaces": {
@@ -151,6 +154,7 @@ Terraform Cloud does not allow global variable sets to contain conflicting varia
151154
| `data.name` | string | | The name of the variable set. |
152155
| `data.description` | string | | Text displayed in the UI to contextualize the variable set and its purpose. |
153156
| `data.global` | boolean | | When true, Terraform Cloud automatically applies the variable set to all current and future workspaces in the organization. |
157+
| `data.priority` | boolean | `false` | When true, the variables in the set override any other variable values set in a more specific scope including values set on the command line. |
154158
| `data.relationships.workspaces` | array | | **Optional** Array of references to workspaces that the variable set should be assigned to. Sending an empty array clears all workspace assignments. |
155159
| `data.relationships.projects` | array | | **Optional** Array of references to projects that the variable set should be assigned to. Sending an empty array clears all project assignments. |
156160
| `data.relationships.vars` | array | | **Optional** Array of complete variable definitions to add to the variable set. |
@@ -170,7 +174,8 @@ Terraform Cloud does not allow global variable sets to contain conflicting varia
170174
"attributes": {
171175
"name": "MyVarset",
172176
"description": "Full of vars and such for mass reuse. Now global!",
173-
"global": true
177+
"global": true,
178+
"priority": true,
174179
},
175180
"relationships": {
176181
"workspaces": {
@@ -226,7 +231,8 @@ curl \
226231
"attributes": {
227232
"name": "MyVarset",
228233
"description": "Full of vars and such for mass reuse. Now global!",
229-
"global": true
234+
"global": true,
235+
"priority": true
230236
},
231237
"relationships": {
232238
"vars": {
@@ -298,6 +304,7 @@ curl \
298304
"name": "MyVarset",
299305
"description": "Full of vars and such for mass reuse",
300306
"global": false,
307+
"priority": false,
301308
"updated-at": "2023-03-06T21:48:33.588Z",
302309
"var-count": 5,
303310
"workspace-count": 2,
@@ -411,6 +418,7 @@ All of the list endpoints support pagination [with standard URL query parameters
411418
"name": "MyVarset",
412419
"description": "Full of vars and such for mass reuse",
413420
"global": false,
421+
"priority": false,
414422
"updated-at": "2023-03-06T21:48:33.588Z",
415423
"var-count": 5,
416424
"workspace-count": 2,

website/docs/cloud-docs/workspaces/variables/index.mdx

+23
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,26 @@ When you trigger a run through the command line, Terraform Cloud applies the fol
152152
- **C_Variable_Set:** `KEY2`. For this run, `KEY2` equals `c`. This is a global variable set with no overwritten values.
153153

154154
![An example scenario demonstrating variable precedence in Terraform Cloud](/img/docs/variable-precedence-example.png)
155+
156+
157+
## Precedence with Priority Variable Sets
158+
159+
You can select to prioritize the values of variables in a variable set in the UI and or mark a variable set as `priority: true`.
160+
When a variable set is prioritized the values take precedence over any variables with the same key set at a _more specific_ scope.
161+
162+
* A project scope is more specific than a global scope.
163+
* A workspace variable set scope is more specific than a project scope.
164+
* A workspace variable scope is more specific than a workspace variable set scope.
165+
* A variable set on the command line a more specific scope than a workspace variable.
166+
167+
Therefore a prioritized global variable set variable takes precedence over even a variable set by a command line argument.
168+
169+
A variable from a prioritized global variable set takes precedence over any variables set by any of the methods above except for
170+
those set directly in the terraform configuration code itself.
171+
172+
If two prioritized variable sets include the same variable key, precedence is determined by the alphabetical order of variable
173+
set name.
174+
175+
The only variable that a prioritized variable set variable cannot overwrite is one with a value set directly in the terraform
176+
configuration code itself. If you want to ensure what a variable value is including the terraform configuration code itself,
177+
we recommend using a Policy Check or Run Task.

website/docs/cloud-docs/workspaces/variables/managing-variables.mdx

+6
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ To overwrite a variable from a variable set, [create a new workspace-specific va
148148

149149
Variables within a variable set can also automatically overwrite variables with the same key in other variable sets applied to the same workspace. Though variable sets are created for the organization, these overwrites occur within each workspace. Refer to [variable precedence](/terraform/cloud-docs/workspaces/variables#precedence) for more details.
150150

151+
## Priority Variable Sets
152+
153+
You can select to prioritize variable values from a variable set over any other variables with the same key set at more specific scopes. Variables from prioritized variable sets will also overwrite variables with the same key that are set from the command line, .*auto.tfvars files, and terraform.tfvars files.
154+
155+
The only variable values that a prioritized variable set cannot overwrite are values set directly in the terraform configuration itself. If you want to fully ensure the values of variables including values in your terraform configuration code, we recommend using a Policy Check or Run Task.
156+
151157
## Variable Values and Format
152158

153159
The limits, allowable values, and required format are the same for both workspace-specific variables and variable sets.

0 commit comments

Comments
 (0)