Creating Network Resources in Azure with Terraform

30 minutes
  • 5 Learning Objectives

About this Hands-on Lab

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.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Set Up Cloud Shell and the Lab Environment

In the Portal

  1. Go to the Azure Portal and log in using your lab credentials.
  2. Click the Cloud Shell icon next to the search bar in the Portal.
  3. Select Bash at the prompt.
  4. Click Show Advanced Settings
  5. Set the Cloud Shell region to the same location as the resource group.
  6. Select the existing resource group, and select Use Existing for the storage account.
  7. In the File share section, choose Create new and enter terraform
  8. Click Attach Storage.
  9. Download the script at
  10. Add execute permissions to the script.
  11. Run the  []() script.
Import the Resource Group into Terraform

In the Cloud Shell

1.. In the Cloud Shell, review the file.

  1. Make note of the resource group name and label at the top and then close the file.
  2. Run the az group list command to get the subscription ID.
  3. Import your resource group into Terraform using the resource name, label, and subscription ID.
  4. After the import, add the name and location of your resource group to the 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>"
  5. Save the file.
Add the Networking Configuration

In the Cloud Shell

  1. Edit the file.
  2. Add a virtual network with the label comics, the name vnet, and an address space of
  3. Add a subnet with the label comics, the name subnet, and an address prefix of
  4. Add a public IP with the label comics, the name publicIpForLB, and an allocation method of Static .
  5. Save the changes.
Add the Load Balancer Configuration

1) Create a file called
2) Add the load balancer configuration with the label comics, the name loadBalancer, and a frontend IP configuration that uses the public IP you created in the file.
3) Add the load balancer backend address pool configuration with the label comics and the name BackendAddressPool.
4) Save the changes.

Apply the Configuration
  1. Validate your Terraform configuration.
  2. Apply your configuration.
  3. Confirm your resources were deployed to Azure.

Additional Resources

You have been asked to start building out the network for an app server cluster for a comic reader that you are working on for the site for digital comics. You need to build a solid foundation of network resources for your cluster to use, which includes a virtual network, subnets, a public IP, a network security group, and a load balancer. You have a resource group that was deployed that you will be using. Import your resource group, build out your Terraform configuration, and deploy the network infrastructure with Terraform to Azure.

Now that we have a plan, let’s put it into action!

What are Hands-on Labs

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.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?