- Lab
- A Cloud Guru
Discover and Import Existing Resources
Welcome to the Discover and Import Existing Resources lab. In this lab, we will cover three objectives: 1. Explore existing resources in Azure 2. Install and use the Azure Export for Terraform tool 3. Refactor the produced configuration By the end of this lab you'll be ready to use the Azure Export for Terraform tool to bring existing resources under management by Terraform.
Path Info
Table of Contents
-
Challenge
Explore existing resources in Azure
In this objective, you'll use the Azure portal to explore the virtual network that you'll be importing into a Terraform configuration.
- Log into the Azure portal using the provided credentials and link
- Browse the contents of the resource group, noting the resource group name
- Examine the virtual network and note the settings
-
Challenge
Install and use the Azure Export for Terraform tool
In this objective, you'll install the Azure Export for Terraform tool and use it to create a Terraform configuration to manage the virtual network. Note that you will not be managing the resource group that contains the virtual network.
- Install the Azure Export for Terraform tool following the installation instructions found at the link.
- Log into Azure using the Azure CLI and the provided lab credentials:
az login
- Create a directory to hold the imported configuration and state
- In the directory, run the
aztfexport
tool and pass it the resource group name:
aztfexport rg "RESOURCE_GROUP_NAME"
- Skip the resource group and import the rest of the resources
- Verify the created configuration and state data
-
Challenge
Refactor the produced configuration
Although Azure Export for Terraform created the configuration for you and imported state, you still need to make some adjustments to the configuration to make it usable and more flexible. In this objective, you'll update the provider block, add the resource group as a data source, and replace hardcoded values with references.
- Update the
azurerm
provider block to include theskip_provider_registration = true
argument - Add an
azurerm_resource_group
data source that takes an input variable ofresource_group_name
- Add the
resource_group_name
input variable - Update the hardcoded resource group name and location values with a data source reference
- Update the subnets with resource references to the virtual network
- Remove the
depends_on
blocks - Add a
terraform.tfvars
file with theresource_group_name
variable value - Run a
terraform plan
to confirm that no infrastructure changes are required
- Update the
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.