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

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
Labs

Path Info

Level
Clock icon Advanced
Duration
Clock icon 15m
Published
Clock icon Jun 17, 2022

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.

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