In this lab, you are asked to start building out an app server cluster for a comic reader that you are working on for your employer for digital comics. To do this, you will configure Cloud Shell and run the lab setup script; import the resource group; deploy the Azure Storage account configuration; and add the VM cluster configuration and deploy your cluster.
Learning Objectives
Successfully complete this lab by achieving the following learning objectives:
- Set Up Cloud Shell and the Lab Environment
In the Portal
- Click the Cloud Shell icon next to the search bar in the portal.
- Select Bash at the prompt.
- Click Show advanced settings.
- Set the Cloud Shell region to the same location as the resource group.
- Select the existing resource group, and select Use existing for the Storage account.
- In the File share section, choose Create new and enter terraform.
- Click Create storage.
- Download the
lab_5_setup.sh
script: https://raw.githubusercontent.com/ACloudGuru/advanced-terraform-with-azure/main/lab_vm_cluster_resources/lab_5_setup.sh - Add execute permissions to the script.
- Run the
lab_5_setup.sh
script.
- Import the Resource Group
In the Cloud Shell
In the Cloud Shell, review the
networking.tf
file.Make note of the resource group and label, and then close the file.
Run the
az group list
command to get the subscription ID.Import your resource group into Terraform using the resource name, label, and subscription ID.
After the import, add the name and location of your resource group to the
networking.tf
file so it looks like the code below (fill in with your resource group and location):resource "azurerm_resource_group" "comics" { name = "<RESOURCE_GROUP>" location = "<LOCATION>" }
Save the file.
- Define Your Cluster Config and Output Variables
In the Cloud Shell
- Create a file called
vms.tf
. - Define the VM configuration so it will deploy a two-VM cluster using count.
- Make sure you associate your VMs with your subnet and load balancer backend pool in the
networking.tf
file, and adjust for the multiple resources in your configuration. - Save the changes.
- Create a file called
output.tf
. - Define the these outputs:
- Resource group
- Private IP of the first VM
- Private IP of the second VM
- Public IP
- Resource group location
- Save the changes.
- Create a file called
- Add the VM Cluster Terraform Config and Deploy
In the Cloud Shell
- Apply your configuration.
- Confirm you have successfully deployed your VM cluster.