Featured resource
2025 Tech Upskilling Playbook
Tech Upskilling Playbook

Build future-ready tech teams and hit key business milestones with seven proven plays from industry leaders.

Check it out
  • Lab
    • Libraries: If you want this lab, consider one of these libraries.
    • Cloud
Azure icon
Labs

Import Existing Resources into Terraform from Azure

Hey, Gurus! Welcome to the lab. In this lab, we will cover three objectives. First, we will log into the Azure portal and configure the Cloud Shell to use Bash. Second, we will download and run a script to set up the lab environment. And for our third objective, we will import our existing Azure resource group into our Terraform state, so we can use it to manage our resources. This is something that you will run into when an organization has already established a presence with a cloud provider like Azure and decides to start using Terraform to manage and create infrastructure. More than likely, you will be working with existing resources that you will want to manage or make changes to with Terraform.

Azure icon
Lab platform
Lab Info
Level
Advanced
Last updated
Sep 22, 2025
Duration
15m

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
Table of Contents
  1. Challenge

    Set Up Cloud Shell
    1. Go to the Azure portal and log in using your lab credentials.
    2. Click the Cloud Shell icon next to the search bar in the portal.
    3. Select Bash at the prompt.
    4. Click Show Advanced Settings.
    5. Set the Cloud Shell region to the same location as the resource group.
    6. Select the existing Resource Group, and select Use Existing for the Storage Account.
    7. In the File share section, choose Create new and enter terraform.
    8. Click Create Storage.
  2. Challenge

    Set Up Lab Environment
    1. Download the lab_2_setup.sh script at https://github.com/ACloudGuru/advanced-terraform-with-azure/raw/main/lab_import_existing_resources_into_terraform_from_azure/lab_2_setup.sh.
    2. Add execute permissions to the script.
    3. Run the lab_2_setup.sh script.
    4. Move to the terraform directory.
    5. Initialize the working directory.
  3. Challenge

    Import the Resource Group into Terraform
    1. In the Cloud Shell, create a file called networking.tf.
    2. Add the following resource block and save the file:
      resource "azurerm_resource_group" "guru" {}
      
    3. Run the az group list command to get the subscription id.
    4. Import your resource group into Terraform.
    5. Add 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>"
          tags     = {
              environment = "demo"
          }
      }   
      
    6. Save the file.
    7. Apply your changes and confirm.
About the author

Pluralsight Skills gives leaders confidence they have the skills needed to execute technology strategy. Technology teams can benchmark expertise across roles, speed up release cycles and build reliable, secure products. By leveraging our expert content, skill assessments and one-of-a-kind analytics, keep up with the pace of change, put the right people on the right projects and boost productivity. It's the most effective path to developing tech skills at scale.

Real skill practice before real-world application

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.

Learn by doing

Engage hands-on with the tools and technologies you’re learning. You pick the skill, we provide the credentials and environment.

Follow your guide

All labs have detailed instructions and objectives, guiding you through the learning process and ensuring you understand every step.

Turn time into mastery

On average, you retain 75% more of your learning if you take time to practice. Hands-on labs set you up for success to make those skills stick.

Get started with Pluralsight