- Lab
- A Cloud Guru
Create a VM Cluster in Azure with Terraform
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.
Path Info
Table of Contents
-
Challenge
Set Up Cloud Shell and the Lab Environment
In the Portal
-
Click the Cloud Shell icon (
>_
) in the upper right. -
Select Bash.
-
In the Getting started pane, select No storage account required for an ephemeral session.
-
Using the dropdown menu, select the only subscription available.
-
Click Apply.
-
In Cloud Shell, create the clouddrive directory:
mkdir clouddrive
-
Change directory:
cd clouddrive
-
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.
-
-
Challenge
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.
-
-
Challenge
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
-
Challenge
Add the VM Cluster Terraform Config and Deploy
In the Cloud Shell
- Apply your configuration.
- Confirm you have successfully deployed your VM cluster.
What's a lab?
Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.
Provided environment for hands-on practice
We will provide the credentials and environment necessary for you to practice right within your browser.
Guided walkthrough
Follow along with the author’s guided walkthrough and build something new in your provided environment!
Did you know?
On average, you retain 75% more of your learning if you get time for practice.