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.
Learning Objectives
Successfully complete this lab by achieving the following learning objectives:
- 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.
- 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
- 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