- Lab
- A Cloud Guru
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.
Path Info
Table of Contents
-
Challenge
Set Up Cloud Shell
- Go to the Azure portal and log in using your lab credentials.
- Click the Cloud Shell icon next to the search bar in the portal.
- Select Bash at the prompt.
- Click Show Advanced Settings.
- Set the Cloud Shell region to the same location as the resource group.
- Select the existing Resource Group, and select Use Existing for the Storage Account.
- In the File share section, choose Create new and enter terraform.
- Click Create Storage.
-
Challenge
Set Up Lab Environment
- Download the
lab_2_setup.sh
script athttps://github.com/ACloudGuru/advanced-terraform-with-azure/raw/main/lab_import_existing_resources_into_terraform_from_azure/lab_2_setup.sh
. - Add execute permissions to the script.
- Run the lab_2_setup.sh script.
- Move to the
terraform
directory. - Initialize the working directory.
- Download the
-
Challenge
Import the Resource Group into Terraform
- In the Cloud Shell, create a file called
networking.tf
. - Add the following resource block and save the file:
resource "azurerm_resource_group" "guru" {}
- Run the
az group list
command to get the subscription id. - Import your resource group into Terraform.
- 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" } }
- Save the file.
- Apply your changes and confirm.
- In the Cloud Shell, create a file called
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.