- Lab
-
Libraries: If you want this lab, consider one of these libraries.
- Cloud

Creating Network Resources in Azure with Terraform
Hey, Gurus! Welcome to the Creating Network Resources in Azure with Terraform lab. In this lab, we will cover these 4 objectives: 1. First, we will log into the Azure Portal and configure the Cloud Shell, and then download and run the lab setup script to setup the lab. 1. Second, we will import the resource group. 1. Third, we will add the virtual network, subnet, and a network security group. 1. And for the fourth objective, we will add a load balancer. These are resources that will be the foundation for VMs and other resources.

Lab Info
Table of Contents
-
Challenge
Set Up Cloud Shell and the Lab Environment
In the Portal
- Go to the Azure Portal and log in using your lab credentials.
- 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 Attach Storage.
- Download the
lab_4_setup.sh
script athttps://raw.githubusercontent.com/ACloudGuru/advanced-terraform-with-azure/main/lab_network_resources/lab_4_setup.sh
. - Add execute permissions to the script.
- Run the lab_4_setup.sh script.
-
Challenge
Import the Resource Group into Terraform
In the Cloud Shell
1.. In the Cloud Shell, review the
networking.tf
file.- Make note of the resource group name and label at the top 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" "guru" { name = "<RESOURCE_GROUP>" location = "<LOCATION>" }
- Save the file.
-
Challenge
Add the Networking Configuration
In the Cloud Shell
- Edit the
networking.tf
file. - Add a virtual network with the label
comics
, the namevnet
, and an address space of10.0.0.0/16
. - Add a subnet with the label
comics
, the namesubnet
, and an address prefix of10.0.2.0/24
. - Add a public IP with the label
comics
, the namepublicIpForLB
, and an allocation method ofStatic
. - Save the changes.
- Edit the
-
Challenge
Add the Load Balancer Configuration
- Create a file called
lb.tf
. - Add the load balancer configuration with the label
comics
, the nameloadBalancer
, and a frontend IP configuration that uses the public IP you created in thenetworking.tf
file. - Add the load balancer backend address pool configuration with the label
comics
and the nameBackendAddressPool
. - Save the changes.
- Create a file called
-
Challenge
Apply the Configuration
- Validate your Terraform configuration.
- Apply your configuration.
- Confirm your resources were deployed to Azure.
About the author
Real skill practice before real-world application
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.
Learn by doing
Engage hands-on with the tools and technologies you’re learning. You pick the skill, we provide the credentials and environment.
Follow your guide
All labs have detailed instructions and objectives, guiding you through the learning process and ensuring you understand every step.
Turn time into mastery
On average, you retain 75% more of your learning if you take time to practice. Hands-on labs set you up for success to make those skills stick.