- Lab
- A Cloud Guru
Create Azure NSGs with Terraform
This lab demonstrates the ease with which we can deploy and manage a Network Security Group. NSGs provides a simple mechanism to filter traffic to and from an Azure internal network. However, NSGs are somewhat limited in the number of rules you can have in place and keeping track of what rules apply in what priority can occasionally have you pulling out your hair. Terraform provides a straightforward way to ensure that new NSGs automatically acquire any base rules required by your IT department, and will allow you to make updates as well as re-order rule priorities without having to manually destroy NSG rules before recreating them.
Path Info
Table of Contents
-
Challenge
Log into the Azure Portal and set up the Azure CLI for use.
- Open the CLI.
- Select Bash at the prompt.
- Click Show Advanced Settings. Both the Resource Group and Storage Account should be pre-selected with the lab generated values.
- In the File share section, choose the Create new radio button and enter console.
- Click the Attach Storage button.
- Once the command prompt is initialized, proceed to Task 2.
-
Challenge
Deploy a Network Security Group with inbound/outbound rules.
To complete this exercise, please make sure you've completed Task 1.
- Use the code block found in the Additional Information and Resources section to create a
lab.tf
file and upload it to the CLI. - In the (resource
"azurerm_storage_account" "lab"
) declaration, you'll need to edit theresource_group_name
value with the name generated by the lab. Additionally, you'll need to enter a unique name for the storage account that will be used for the file share. The"provider"
statement has been added to the code, so you won't need to create amain.tf
file to deploy the storage account. - Once the file has been uploaded, run
terraform init
. - Run
terraform plan
and review the output to confirm that Terraform will create the desired resource. Green plus signs will indicate the resources that need to be added. - Run
terraform apply
, answering yes to the prompt to continue. - Once Terraform completes the deployment, check the Azure Portal to confirm.
You're done! Go ahead and shut down the lab.
- Use the code block found in the Additional Information and Resources section to create a
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.