Azure Storage (azurerm) Backend
Example configuration:
remote_state { backend = "azurerm" config = { storage_account_name = "myterragruntstate" container_name = "tfstate" key = "${path_relative_to_include()}/tofu.tfstate" resource_group_name = "tofu-rg" subscription_id = "00000000-0000-0000-0000-000000000000" use_azuread_auth = true }}Terragrunt-only bootstrap settings are set in the same config block:
remote_state { # ...
config = { # ...
location = "eastus" enable_soft_delete = true soft_delete_retention_days = 14 }}Creating a storage account grants no access to the blobs inside it, so an identity using
use_azuread_auth can create the account and still read state as unauthorized.
Set assign_blob_data_role to have bootstrap grant Storage Blob Data Contributor on the
account, which closes that gap:
remote_state { backend = "azurerm" config = { # ...
use_azuread_auth = true assign_blob_data_role = true }}The role is granted to the identity Terragrunt authenticated as. Set principal_id to
the object id of a user, group, or service principal to grant it to someone else instead.
The assignment is skipped when it already exists, so reruns need no write permission.
This is opt-in because creating a role assignment requires
Microsoft.Authorization/roleAssignments/write (held by Owner and User Access
Administrator, but not Contributor), which many CI identities deliberately lack.
When bootstrapping (terragrunt backend bootstrap or --backend-bootstrap), Terragrunt creates the resource group,
storage account, and blob container when they do not exist (each step can be skipped with the skip_* options below),
then enables blob versioning and, when requested, soft delete on both new and pre-existing accounts.
The following config options are only valid for the azurerm backend and are used by Terragrunt; they are not passed on to OpenTofu/Terraform:
-
location- Azure region for the resource group and storage account (e.g.eastus). Required when Terragrunt creates them. -
account_kind- Storage account kind. Defaults toStorageV2. -
account_tier- Storage account tier,StandardorPremium. Defaults toStandard. -
account_replication_type- Replication type, e.g.LRS,GRS,ZRS. Defaults toLRS. -
access_tier- Blob access tier,Hot,Cool,Cold, orPremium. Defaults toHot. -
minimum_tls_version- Minimum TLS version permitted on requests to the storage account,TLS1_2orTLS1_3. Defaults toTLS1_2. The deprecatedTLS1_0andTLS1_1are not accepted. Applies only when Terragrunt creates the account. -
tags- Map of tags applied to the storage account on creation. -
skip_resource_group_creation- Whentrue, never create the resource group. -
skip_storage_account_creation- Whentrue, never create the storage account; it must already exist. -
skip_container_creation- Whentrue, never create the blob container; it must already exist. -
skip_versioning- Whentrue, do not enable blob versioning on the account. -
enable_soft_delete- Whentrue, enable blob and container soft delete. -
soft_delete_retention_days- Soft delete retention in days, 1 to 365. Defaults to 7 when unset; values outside 1 to 365 are clamped to 7 at bootstrap (a warning is logged). -
allow_blob_public_access- Whentrue, allow containers on the account to permit anonymous access. Defaults tofalse. -
msi_resource_id- Resource ID of a user-assigned managed identity to use withuse_msi. -
environment- Azure cloud partition:public(default),usgovernment(Azure Government), orchina. Also accepted viaARM_ENVIRONMENT. -
assign_blob_data_role- Whentrue, bootstrap grants Storage Blob Data Contributor on the storage account toprincipal_id(or to the identity Terragrunt authenticated as when unset). Opt-in because it requiresMicrosoft.Authorization/roleAssignments/write. -
principal_id- Microsoft Entra object id that receives the data-plane role whenassign_blob_data_roleistrue. Defaults to the caller resolved from the access token.
Authentication is resolved in the following order, with ARM_* and AZURE_* environment variable fallbacks applied
to any values not set in the config:
- SAS token (
sas_token) - Storage account access key (
access_key) - Service principal (
client_id,client_secret,tenant_id) - Managed identity (
use_msi, optionallymsi_resource_id) - OIDC / workload identity (
use_oidc,oidc_token_file_path) - Azure AD (
use_azuread_auth, or the default credential chain, which honorsaz login)
For Azure Government, set environment = "usgovernment" (or ARM_ENVIRONMENT=usgovernment) so Terragrunt
talks to the Government endpoints for auth, ARM, and blob storage. Credentials must come from that partition
(for example az cloud set --name AzureUSGovernment then az login, or a Government tenant service principal).
Bootstrap and assign_blob_data_role use the same keys as public cloud; built-in role definition IDs
(including Storage Blob Data Contributor) are the same across partitions per
Understand Azure role definitions.
remote_state { backend = "azurerm" config = { # ...
environment = "usgovernment" use_azuread_auth = true assign_blob_data_role = true }}