VCS structure & workspaces

Variable sets allow Terraform Cloud users to reuse both Terraform-defined and environment variables not just from root to child modules, but across certain workspaces or an entire organization.

If you use a multi-folder structure instead of a mono-folder, where you application is split into separate folders or branches but within the same repository, such as the example below, you may want to have seperate Terraform cloud workspaces for each folder so you can control what happens and when. Maybe you have three application folders based on environment type (prod, test, dev) and you only want to execute changes in one environment type when a change it made. You could setup the workspace to react only when a certain branch is changed and use the a branch name that matches the environment and working directory. Or you you target changes made in working directories that are split based on environment type.

In the example below, we have two GitHub repositories. One dedicated to the application and one to Terraform modules. The main.tf file for the application code calls the module code from the second repository. In Terraform cloud we have one project dedicated to the application repository so we can control who has access and what they can do. Within this project we have a workspace dedicated per application; so appA and appB. The workspace is set to apply automatically. To control that the apply is only executed against code that is changed we configure the VCS settings per module with the following specific settings:

  • Terraform working directory is set to the folder containg the code. So appA for example
  • Run triggers is set to Only trigger runs when files in specificed paths changeand the working directory path is set as the value using a prefix

Example GitHub multi-repo and multi-folder setup image

Last modified July 21, 2024: update (e2ae86c)