5. Run Terraform Deployment
Select the Terraform Workspace to use
The Terraform workspace allows us to separate the state of individual environments (eg. Dev, Uat, Prod), which is stored in the avocarisktfstorage Storage Account.
Before making changes to any of the environments, make sure you are using the right workspace. To see the workspace in use, use the following command:
terraform workspace show
This will display the name of the environment, such as ar-dev.
To select the workspace we want, such as ar-uat, we have two possibilities: using the workspace select command or by setting the TF_WORKSPACE environment variable:
terraform workspace select ar-uat
export TF_WORKSPACE=ar-uat
When a deployment to a new environment is made, and the coresponding workspace does not exist, you can create a new workspace by using the workspace new subcommand in Terraform, like in the following example :
terraform worspace new ar-perf-test
Once the workspace is created using the previously shown command, Terraform will automatically make it the current one.
Apply the resource changes over the current Terraform workspace / environment.
Once you have selected the right workspace, you can apply the changes using the following command (replace <environment> with the name of your environment / workspace and <service-principal-secret> with the secret/password of the Service Principal previously created):
terraform apply \
-var="environment=<environment>" \
-var="AZ_SECRET=<service-principal-secret>"
This command will check the changes made on the Terraform resources, by checking the state stored in the storage account and also the resources available in Azure. Once the differences are detected, Terraform will display the plan it computed, with all the new/updated/deleted resources.
Confirming the plan and executing it is done by typing "yes".