· Documentation  · 1 min read

Use azure storage as backend for terraform state

Lets directly jump into the implementation.

Lets directly jump into the implementation.

Overview

Let’s see how to use Azure Storage account as backend in Terraform.

Steps

  1. 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
  1. Create new storage account as terraform_backend on terraform_resource_group resource group
az storage account create --resource-group terraform_resource_group --name terraform_backend --sku Standard_LRS --encryption-services blob
  1. Create new blob container on created storage account as my_service_name
az storage container create --name my_service_name --account-name terraform_backend
  1. 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 {}
}
  1. 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"
  }
}
Back to Blog

Related Posts

View All Posts »
AstroWind template in depth

AstroWind template in depth

While easy to get started, Astrowind is quite complex internally. This page provides documentation on some of the more intricate parts.