Azure Resource Manager (ARM) template that creates an Azure Storage account to store Terraform state files:
- Creates a storage account with the specified name.
- Configures the storage account according to security recommendations.
- Creates a blob container with the specified name.
- Grants access to the storage account for specified user, group and service principals.
- Creates a read-only lock to prevent changes to the storage account.
- Sign up for an Azure account.
- Install Azure CLI version 2.20 or later.
- Install Terraform.
-
Login to Azure:
az login
-
Set active subscription:
az account set --name <SUBSCRIPTION_NAME>
-
Create resource group:
az group create --name <RESOURCE_GROUP_NAME> --location <LOCATION>
Requires Azure role
Contributor
at subscription. -
Create a deployment at resource group from the template URI:
az deployment group create --name terraform-backend --resource-group <RESOURCE_GROUP_NAME> --template-uri https://raw.githubusercontent.com/equinor/azure-terraform-backend-template/refs/heads/main/azuredeploy.json --parameters storageAccountName=<STORAGE_ACCOUNT_NAME>
Requires Azure role
Owner
at resource group.
-
Create a Terraform configuration file
main.tf
and add the following backend configuration:terraform { backend "azurerm" { resource_group_name = "<RESOURCE_GROUP_NAME>" storage_account_name = "<STORAGE_ACCOUNT_NAME>" container_name = "tfstate" key = "terraform.tfstate" use_azuread_auth = true } }
-
Initialize Terraform backend:
terraform init
Name | Description | Type | Default |
---|---|---|---|
storageAccountName |
The name of the storage account to create. | string |
|
containerName |
The name of the blob container to create. | string |
tfstate |
ipRules |
An array of IP addresses or ranges that should be granted access to the storage account. If empty, all IP addresses and ranges will be granted access to the storage account. | array |
[] |
principalIds |
An array of object IDs for user, group or service principals that should be granted access to the storage account. | array |
[] |
Name | Description | Type |
---|---|---|
storageAccountName |
The name of the storage account that was created. | string |
containerName |
The name of the blob container that was created. | string |
This project is licensed under the terms of the MIT license.