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¶
- Go to your Terraform organization and click on Settings.
- Click on Variable Sets.
- Click on Create variable set.
- 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.
- Save the variable set.
- If a variable is present in the workspace and the variable set then precedence is given to the Workspace variables.
Attaching a variable set¶
- We can either select the variable set to be applied to all the workspace or to a specific one.
- click on Settings.
- Click on Variable Sets.
- Click on the variable set you created which in our case is
common
. - Look at the image to attach the variable set in all workspaces.
- This attached these variables to all the workspaces present in the organization.
- It is not a good practice to use this.
- Look at the image to attach the variable set in 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.
- Save the variable set.