- Lab
- A Cloud Guru
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.
Path 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
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.