In Terraform, there is the concept of workspaces, which enables the same Terraform configuration to be used in order to build multiple environments.
Each of these configurations will be written to a different Terraform state file and will thus be isolated from the other configurations. Workspaces can be used to create several environments of our infrastructure.
In this recipe, we will study the use of Terraform workspaces in the Terraform configuration, with the execution of Terraform commands.
Getting ready
The purpose of this recipe is for an application to create a Resource Group for each of its environments (dev and prod).
Regarding the Terraform configuration, no prerequisites are necessary. We will see it in the steps of the recipe.
The Terraform configuration for this recipe is available here: https://github.com/PacktPublishing/Terraform-Cookbook/tree/master/CHAP04/workspaces
How to do it…
To manage a Terraform workspace, perform...