Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
  • Labs icon Lab
  • A Cloud Guru
Azure icon
Labs

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.

Azure icon
Labs

Path Info

Level
Clock icon Intermediate
Duration
Clock icon 30m
Published
Clock icon May 02, 2024

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. 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.

    1. Log into the Azure portal using the provided credentials and link
    2. Browse the contents of the resource group, noting the resource group name
    3. Examine the virtual network and note the settings
  2. 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.

    1. Install the Azure Export for Terraform tool following the installation instructions found at the link.
    2. Log into Azure using the Azure CLI and the provided lab credentials:
    az login
    
    1. Create a directory to hold the imported configuration and state
    2. In the directory, run the aztfexport tool and pass it the resource group name:
    aztfexport rg "RESOURCE_GROUP_NAME"
    
    1. Skip the resource group and import the rest of the resources
    2. Verify the created configuration and state data
  3. 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.

    1. Update the azurerm provider block to include the skip_provider_registration = true argument
    2. Add an azurerm_resource_group data source that takes an input variable of resource_group_name
    3. Add the resource_group_name input variable
    4. Update the hardcoded resource group name and location values with a data source reference
    5. Update the subnets with resource references to the virtual network
    6. Remove the depends_on blocks
    7. Add a terraform.tfvars file with the resource_group_name variable value
    8. Run a terraform plan to confirm that no infrastructure changes are required

The Cloud Content team comprises subject matter experts hyper focused on services offered by the leading cloud vendors (AWS, GCP, and Azure), as well as cloud-related technologies such as Linux and DevOps. The team is thrilled to share their knowledge to help you build modern tech solutions from the ground up, secure and optimize your environments, and so much more!

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.

Start learning by doing today

View Plans