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
- 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.
- 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.
- 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
- Add the Load Balancer Configuration
1) Create a file called
lb.tf
.
2) Add the load balancer configuration with the labelcomics
, the nameloadBalancer
, and a frontend IP configuration that uses the public IP you created in thenetworking.tf
file.
3) Add the load balancer backend address pool configuration with the labelcomics
and the nameBackendAddressPool
.
4) Save the changes.- Apply the Configuration
- Validate your Terraform configuration.
- Apply your configuration.
- Confirm your resources were deployed to Azure.