- Lab
-
Libraries: If you want this lab, consider one of these libraries.
- Cloud

Setting Up Remote State Storage
Welcome to the Setting Up Remote State Storage lab. In this lab, we will cover three objectives: 1. Create an Azure Storage Account 1. Deploy a virtual network with the local backend 1. Update the backend and migrate state data By the end of this lab, you will know how to configure a Terraform deployment to use the `azurerm` backend and how to migrate existing state data.

Lab Info
Table of Contents
-
Challenge
Create an Azure Storage Account
In this objective, you'll create an Azure Storage account using Terraform. Make sure to include the storage account name in the outputs.
- Log into Azure using the Azure CLI.
- Create a new folder to hold a Terraform Configuration to deploy a storage account.
- Add a provider block for the
azurerm
provider withskip_provider_registration
andstorage_use_azuread
set totrue
. - Add the existing resource group as a data source.
- Create a random integer resource to generate a unique storage account name.
- Create an Azure Storage account with the following settings:
- HTTPS traffic only: Enabled
- Shared access key: Disabled
- Default to OAuth authentication: Enabled
- Create a container in the storage account named
tfstate
. - Initialize and deploy the Terraform configuration.
- Make note of the storage account name for the next objective.
-
Challenge
Deploy a Virtual Network with the Local Backend
In this objective, you'll deploy a simple virtual network configuration using the local backend. The configuration will be updated in the next objective to use the
azurerm
backend instead.- Create a new folder to hold a Terraform Configuration to deploy a virtual network.
- Add a provider block for the
azurerm
provider withskip_provider_registration
andstorage_use_azuread
set totrue
. - Add the existing resource group as a data source.
- Add an
azurerm_virtual_network
resource. - Initialize and deploy the Terraform configuration.
-
Challenge
Update the Backend and Migrate State Data
In this objective, you'll update the virtual network configuration to use the
azurerm
backend with a partial configuration. Then you'll initialize the configuration to migrate the existing state data to the storage account created in the first objective.- Update you configuration to use the
azurerm
backend with a partial configuration. - Create a backend configuration file with
use_azuread_auth
set totrue
. - Use the storage account name from the first objective and the existing resource group name in the backend configuration.
- Run
terraform init
to initialize the configuration and migrate state data. - Accept the migration prompt to copy the state data to the storage account.
- Verify the state data is stored in the storage account container.
- Update you configuration to use the
About the author
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.