Store Terraform state in Azure Blob Storage¶
When you finish, every terraform apply for your Azure cluster reads and writes its state in a blob container that keeps every prior revision of your state.
Before you start¶
- An Azure subscription with Contributor permissions
- Terraform 1.11 or later
1. Create a storage account and container¶
az group create -n tfstate-rg -l eastus2
az storage account create -n tfstatequmulo -g tfstate-rg -l eastus2 --sku Standard_LRS
az storage container create -n tfstate --account-name tfstatequmulo
The last command prints "created": true.
2. Point Terraform at the container¶
terraform {
backend "azurerm" {
resource_group_name = "tfstate-rg" # <-- Replace with your resource group
storage_account_name = "tfstatequmulo" # <-- Replace with your storage account
container_name = "tfstate" # <-- Replace with your container name
key = "qumulo/azure/prod.tfstate" # <-- Replace with your path in the container
}
}
Run terraform init -upgrade. If local state already exists, Terraform offers to migrate it into the container.
The output ends with Successfully configured the backend "azurerm"!
3. Lock down the container¶
Turn on versioning and keep deleted blobs recoverable for 30 days.
az storage account blob-service-properties update \
--account-name tfstatequmulo \
--resource-group tfstate-rg \
--enable-versioning true \
--enable-delete-retention true \
--delete-retention-days 30
Confirm that versioning is on.
az storage account blob-service-properties show \
--account-name tfstatequmulo \
--resource-group tfstate-rg \
--query isVersioningEnabled
The command prints true.
Next¶
Deploy your cluster with the basic Azure cluster example. When you need another backend option, see the Terraform azurerm backend reference.