Use Output Variables to Query Data in Azure Using Terraform

15 minutes
  • 3 Learning Objectives

About this Hands-on Lab

Hey there, Gurus! Welcome to the lab! In this lab, we will demonstrate the usefulness of adding output variables to your configuration and how they can be used to collect data about resources in your infrastructure. In this lab, we will first deploy the virtual network to test deploying to the new Azure test environment, along with a subnet. You will then add some output variables to a file to output the virtual network name and the subnet name, expanding on your configuration and adding some outputs that you can use later to easily access these values. Once you have finished testing, you will then destroy your test infrastructure.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Deploy the Infrastructure

1) In the CLI, download the lab-azure-outputs.zip file from the lab GitHub repo: https://raw.githubusercontent.com/linuxacademy/content-terraform-2021/main/lab-azure-outputs.zip
2) Unzip the lab-azure-outputs.zip file.
3) Change to the lab-azure-outputs working directory.
4) Review the Terraform configuration file.
5) Add the labs Azure Resource Group name to the configuration.
6) Initialize the working directory.
7) Apply the Terraform configuration.

Add the Outputs Variable File

1) In the CLI, download the outputs_azure.tf file from the lab GitHub repo: https://raw.githubusercontent.com/linuxacademy/content-terraform-2021/main/outputs_azure.tf
2) Review the outputs_azure.tf file.
3) Apply your changes to the infrastructure.
4) Inspect the ouput of your apply command.
5) Confirm your outputs can be displayed whenever needed.

Destroy the Test Infrastructure

1) Destroy your infrastructure after successful deployment.
2) Confirm destruction.

Additional Resources

You are an admin who supports one of the largest online comic book retailers in the world. You are one of a handful of admins who have been assigned to use Terraform to manage the companies cloud deployments. You are started putting together the first pieces of your first Terraform configuration to deploy your test environment in Azure. First, you will need to deploy continue to test your deployment. You will deploy your virtual network and subnet. You will then add an ouputs configuration file to your Terraform configuration that will use output variables to query the virtual network name and the subnet name to easily look this information up when needed.

Configuration used in this lab: Terraform Config Files -https://raw.githubusercontent.com/linuxacademy/content-terraform-2021/main/lab-azure-outputs.zip Added Terraform Outputs Config File -https://raw.githubusercontent.com/linuxacademy/content-terraform-2021/main/outputs_azure.tf

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?