Variables
Variables
In Terraform, a variable is a way to store and reuse values throughout your Terraform code, and it is defined using the variable block.
Action items on the Variables window
Shared below is the screenshot of the Variables window, numbered with action items/features available on this screen, followed by their brief description.

1
Add Variable (+)
To create a new variable. (Explained in detail below).
2
Search option
To search for a specific variable on the Variables window. Keyword search is supported.
3
Filter
Using this option, you can filter the list of variables by scope or by the user who updated the variable. So, you have the following three options: - All (no filter). - Scope: architecture, environment, project, organization. - Updated by: select the user name whose updated variables you want to view.
4
Sorting variables list
You can sort the list of variables according to ascending or descending order of their names, as well as in ascending/descending order of the date when they were last updated.
5
Filter
The scope selector allows you to view variables that are defined in every scope or display all variables of all scopes.
6
Expand all / Collapse all
Clicking this will exapnd the variables section for you to view details of each variable in the list. Clicking it again will collapse the expanded view.
Creating a new variable
To create a new variable, expand the right panel, and follow these steps:
Click the
Variableicon available in the right panel.Then, click the
+icon to add/import variables. It opens the Create Variable modal.

After that, you can either create a variable manually or you can click on the
Importoption to import already defined variables from an external file (tfvars,tf).

On the "Create variable" form, you can specify the following information:
Name of the variable: This is the name that you'll use to reference the variable when you use it.
Scope: You can set the level at which you want this variable to be available.

Architecture
Variables that are defined with this scope are only available within this architecture only.
If the same variable is defined in another level as well, the default or values defined at the architecture level overrides any other level.
Environment
Variables defined at the environment level are available to all architectures within the same environment.
Variables defined in this level override those defined at project and organization level.
Project
Variables defined at the project level are available to all environments and architectures within the same project.
Variables defined in this level override those defined at the organization level.
Organization
Variables defined at the organization level are available to all architectures, environments and project within the organization.
Description: It should concisely explain the purpose of the variable and what kind of value is expected. This description string might be included in documentation about the module, and so it should be written from the perspective of the user of the module rather than its maintainer.
Variable type: This allows you to restrict the type of value that will be accepted.
While type constraints are optional, we recommend specifying them; they can serve as helpful reminders for users of the module, and they allow Terraform to return a helpful error message if the wrong type is used.

Default value: If present, the variable is considered to be optional and the default value will be used if no value is set.
Value: The value that will be used during Terraform execution and if defined, it overrides the default value.
This value will be put in the file
terraform.tfvars.If you convert the architecture into a template or clone the architecture, this value will be removed.
Sensitive: Setting this flag prevents Terraform from showing its value in the
planorapplyoutput and Brainboard will store the variable in a separate vault.
Validation: You can specify custom validation rules for the variable.

Last updated