Using workspaces to deploy to development and production environments
In Chapter 5, Managing Environments, we discussed the two main methods to support multiple environments using Terraform – workspaces and directory structure. In this case, we decide to use workspaces, as our two environments are very similar.
Thus, first, create two workspaces named dev
and prod
:
$ terraform workspace new prod $ terraform workspace new dev
Once we have created the two workspaces, we write two variable definition files (.tfvars
) for each of the two environments. Since we declared many of our variables as optional, the development variable definition file is quite short. It consists mainly of the zone in which we want to deploy the cluster and the names of the various cloud resources:
chap08/dev.tfvars
project_id = "<PROJECT_ID>" region = "us-west1" zone = "us-west1-a" network...