Skip to content

Variable sets

Variable set are group of variables in a Terraform organization which can be applied to specific or all Terraform workspaces. Purpose of a variable set is to group together the variables which are common in workspaces and can be defined in a single place only. For e.g. If you have multiple workspaces using common variable aws_region then this variable can be created inside a variable set.

Creating a Variable set

  1. Go to your Terraform organization and click on Settings. Settings
  2. Click on Variable Sets. Variable Sets
  3. Click on Create variable set. Create Variable Set
  4. Give the variable set a name and then start adding variables to it. Creating variables in a variable set is similar to creating Workspace variables. Variable in variable set
  5. Save the variable set. Creating Variable Set
  6. If a variable is present in the workspace and the variable set then precedence is given to the Workspace variables.

Attaching a variable set

  1. We can either select the variable set to be applied to all the workspace or to a specific one.
  2. click on Settings. Settings
  3. Click on Variable Sets. Variable Sets
  4. Click on the variable set you created which in our case is common. Opening Variable sets
  5. Look at the image to attach the variable set in all workspaces. Attach variable set to all workspaces
    • This attached these variables to all the workspaces present in the organization.
    • It is not a good practice to use this.
  6. Look at the image to attach the variable set in specific workspaces. Attach variable set to specific workspaces
    • Only the workspaces mentioned will get the variable set.
    • It is a recommended practice
    • If you are not able to list the workspaces, start typing the initials of the workspaces and it will filter the required workspace for you.
  7. Save the variable set.

Next Steps