· Documentation · 1 min read
Use azure storage as backend for terraform state
Lets directly jump into the implementation.
Overview
Let’s see how to use Azure Storage account as backend in Terraform.
Steps
- Create new resource group as
terraform_resource_group
if you don’t have using Azure cli
az group create --name terraform_resource_group --location eastus
- Create new storage account as
terraform_backend
onterraform_resource_group
resource group
az storage account create --resource-group terraform_resource_group --name terraform_backend --sku Standard_LRS --encryption-services blob
- Create new blob container on created storage account as
my_service_name
az storage container create --name my_service_name --account-name terraform_backend
- Configure azure providers in terraform
terraform {
required_version = ">=1.0"
required_providers {
azapi = {
source = "Azure/azapi"
version = "1.14.0"
}
azurerm = {
source = "hashicorp/azurerm"
version = "3.113.0"
}
}
}
provider "azurerm" {
skip_provider_registration = "true"
features {}
}
- Finally, configure azure backend in terraform
terraform {
backend "azurerm" {
resource_group_name = "terraform_resource_group"
storage_account_name = "terraform_backend"
container_name = "my_service_name"
key = "terraform.tfstate"
}
}