Migrate Terraform State to Terraform Cloud for Azure

30 minutes
  • 5 Learning Objectives

About this Hands-on Lab

In this hands-on lab, you will learn how to import Azure resources into Terraform state, view objects in Terraform state, and migrate your state to Terraform Cloud. **Note:** To complete this lab, you will need your own free Terraform Cloud account. You can sign up for a free account at [Terraform Cloud](https://app.terraform.io/public/signup).

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Import Existing Resources into Terraform State
  1. Open the existing Terraform configuration file in C:MigrateState.
  2. Initialize the working directory.
  3. Log in to Azure using the Azure CLI.
  4. Import the exsting resource group into your local state.
Inspect the Local State File

Verify the resource group has been imported into the state file using the Terraform CLI.

Configure a Terraform Cloud Workspace
  1. Create a Terraform Cloud Workspace.
  2. Update the main.tf file with the cloud configuration block.
Migrate State to Terraform Cloud

Initialize the working directory and migrate the state file to Terraform Cloud.

Delete the Local State File

Delete the local state file and the state file backup.

Additional Resources

Scenario

As you walk through the lab, consider the following scenario:

You're playing the role of a platform engineer with River City AI.

River City AI specializes in optimizing speech to text for efficiency and accuracy using machine learning. They’re working on next-generation speech recognition for generative AI.

River City AI is already using Amazon Web Services, and due to the success and capabilities of Microsoft’s Data and AI services, they are looking to adopt a multi-cloud environment to drive innovation. Because they are multi-cloud, Terraform is an excellent choice to deploy their infrastructure as code.

You’ll be working with an existing virtual machine that has been configured as an Infrastructure as Code Workstation, with all the required software, including Terraform, the Azure CLI, and Visual Studio Code with the Terraform extension for VS Code installed.

In this lab, you will:

  1. Import existing resources into Terraform state.
  2. Inspect the local state file.
  3. Configure a Terraform Cloud workspace.
  4. Migrate state to Terraform Cloud.
  5. Delete the local state file.

Lab Setup

In this lab, you will be connecting to the VM using Remote Desktop, and you will have access to the Azure portal.

Note: To complete this lab, you will need to use a remote desktop client.

If you get stuck, feel free to check out the lab objectives or the solution video. Good luck!

WARNING: Be Prepared for UI Changes Given the fluid nature of Microsoft's cloud tools, you may experience user interface (UI) changes that were made following the development of this hands-on lab that do not match up with the lab instructions. When any such changes are brought to our attention, we will attempt to update the content accordingly. However, if changes occur, you will have to adapt to the changes and work through them in the hands-on labs as needed.

What are Hands-on Labs

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.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?