github.com/hugorut/terraform@v1.1.3/website/docs/language/settings/backends/azurerm.mdx (about) 1 --- 2 page_title: 'Backend Type: azurerm' 3 description: Terraform can store state remotely in Azure Blob Storage. 4 --- 5 6 # azurerm 7 8 Stores the state as a Blob with the given Key within the Blob Container within [the Blob Storage Account](https://docs.microsoft.com/en-us/azure/storage/common/storage-introduction). 9 10 This backend supports state locking and consistency checking with Azure Blob Storage native capabilities. 11 12 -> **Note:** By default the Azure Backend uses ADAL for authentication which is deprecated in favour of MSAL - MSAL can be used by setting `use_microsoft_graph` to `true`. **The default for this will change in Terraform 1.2**, so that MSAL authentication is used by default. 13 14 ## Example Configuration 15 16 When authenticating using the Azure CLI or a Service Principal (either with a Client Certificate or a Client Secret): 17 18 ```hcl 19 terraform { 20 backend "azurerm" { 21 resource_group_name = "StorageAccount-ResourceGroup" 22 storage_account_name = "abcd1234" 23 container_name = "tfstate" 24 key = "prod.terraform.tfstate" 25 } 26 } 27 ``` 28 29 *** 30 31 When authenticating using Managed Service Identity (MSI): 32 33 ```hcl 34 terraform { 35 backend "azurerm" { 36 resource_group_name = "StorageAccount-ResourceGroup" 37 storage_account_name = "abcd1234" 38 container_name = "tfstate" 39 key = "prod.terraform.tfstate" 40 use_msi = true 41 subscription_id = "00000000-0000-0000-0000-000000000000" 42 tenant_id = "00000000-0000-0000-0000-000000000000" 43 } 44 } 45 ``` 46 47 *** 48 49 When authenticating using Azure AD Authentication: 50 51 ```hcl 52 terraform { 53 backend "azurerm" { 54 storage_account_name = "abcd1234" 55 container_name = "tfstate" 56 key = "prod.terraform.tfstate" 57 use_azuread_auth = true 58 subscription_id = "00000000-0000-0000-0000-000000000000" 59 tenant_id = "00000000-0000-0000-0000-000000000000" 60 } 61 } 62 ``` 63 64 -> **Note:** When using AzureAD for Authentication to Storage you also need to ensure the `Storage Blob Data Owner` role is assigned. 65 66 *** 67 68 When authenticating using the Access Key associated with the Storage Account: 69 70 ```hcl 71 terraform { 72 backend "azurerm" { 73 storage_account_name = "abcd1234" 74 container_name = "tfstate" 75 key = "prod.terraform.tfstate" 76 77 # rather than defining this inline, the Access Key can also be sourced 78 # from an Environment Variable - more information is available below. 79 access_key = "abcdefghijklmnopqrstuvwxyz0123456789..." 80 } 81 } 82 ``` 83 84 *** 85 86 When authenticating using a SAS Token associated with the Storage Account: 87 88 ```hcl 89 terraform { 90 backend "azurerm" { 91 storage_account_name = "abcd1234" 92 container_name = "tfstate" 93 key = "prod.terraform.tfstate" 94 95 # rather than defining this inline, the SAS Token can also be sourced 96 # from an Environment Variable - more information is available below. 97 sas_token = "abcdefghijklmnopqrstuvwxyz0123456789..." 98 } 99 } 100 ``` 101 102 -> **NOTE:** When using a Service Principal or an Access Key - we recommend using a [Partial Configuration](/language/settings/backends/configuration#partial-configuration) for the credentials. 103 104 ## Data Source Configuration 105 106 When authenticating using a Service Principal (either with a Client Certificate or a Client Secret): 107 108 ```hcl 109 data "terraform_remote_state" "foo" { 110 backend = "azurerm" 111 config = { 112 storage_account_name = "terraform123abc" 113 container_name = "terraform-state" 114 key = "prod.terraform.tfstate" 115 } 116 } 117 ``` 118 119 *** 120 121 When authenticating using Managed Service Identity (MSI): 122 123 ```hcl 124 data "terraform_remote_state" "foo" { 125 backend = "azurerm" 126 config = { 127 resource_group_name = "StorageAccount-ResourceGroup" 128 storage_account_name = "terraform123abc" 129 container_name = "terraform-state" 130 key = "prod.terraform.tfstate" 131 use_msi = true 132 subscription_id = "00000000-0000-0000-0000-000000000000" 133 tenant_id = "00000000-0000-0000-0000-000000000000" 134 } 135 } 136 ``` 137 138 *** 139 140 When authenticating using AzureAD Authentication: 141 142 ```hcl 143 data "terraform_remote_state" "foo" { 144 backend = "azurerm" 145 config = { 146 storage_account_name = "terraform123abc" 147 container_name = "terraform-state" 148 key = "prod.terraform.tfstate" 149 use_azuread_auth = true 150 subscription_id = "00000000-0000-0000-0000-000000000000" 151 tenant_id = "00000000-0000-0000-0000-000000000000" 152 } 153 } 154 ``` 155 156 -> **Note:** When using AzureAD for Authentication to Storage you also need to ensure the `Storage Blob Data Owner` role is assigned. 157 158 *** 159 160 When authenticating using the Access Key associated with the Storage Account: 161 162 ```hcl 163 data "terraform_remote_state" "foo" { 164 backend = "azurerm" 165 config = { 166 storage_account_name = "terraform123abc" 167 container_name = "terraform-state" 168 key = "prod.terraform.tfstate" 169 170 # rather than defining this inline, the Access Key can also be sourced 171 # from an Environment Variable - more information is available below. 172 access_key = "abcdefghijklmnopqrstuvwxyz0123456789..." 173 } 174 } 175 ``` 176 177 *** 178 179 When authenticating using a SAS Token associated with the Storage Account: 180 181 ```hcl 182 data "terraform_remote_state" "foo" { 183 backend = "azurerm" 184 config = { 185 storage_account_name = "terraform123abc" 186 container_name = "terraform-state" 187 key = "prod.terraform.tfstate" 188 189 # rather than defining this inline, the SAS Token can also be sourced 190 # from an Environment Variable - more information is available below. 191 sas_token = "abcdefghijklmnopqrstuvwxyz0123456789..." 192 } 193 } 194 ``` 195 196 ## Configuration variables 197 198 The following configuration options are supported: 199 200 * `storage_account_name` - (Required) The Name of [the Storage Account](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/storage_account). 201 202 * `container_name` - (Required) The Name of [the Storage Container](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/storage_container) within the Storage Account. 203 204 * `key` - (Required) The name of the Blob used to retrieve/store Terraform's State file inside the Storage Container. 205 206 * `environment` - (Optional) The Azure Environment which should be used. This can also be sourced from the `ARM_ENVIRONMENT` environment variable. Possible values are `public`, `china`, `german`, `stack` and `usgovernment`. Defaults to `public`. 207 208 * `endpoint` - (Optional) The Custom Endpoint for Azure Resource Manager. This can also be sourced from the `ARM_ENDPOINT` environment variable. 209 210 ~> **NOTE:** An `endpoint` should only be configured when using Azure Stack. 211 212 * `snapshot` - (Optional) Should the Blob used to store the Terraform Statefile be snapshotted before use? Defaults to `false`. This value can also be sourced from the `ARM_SNAPSHOT` environment variable. 213 214 *** 215 216 When authenticating using the Managed Service Identity (MSI) - the following fields are also supported: 217 218 * `resource_group_name` - (Required) The Name of the Resource Group in which the Storage Account exists. 219 220 * `msi_endpoint` - (Optional) The path to a custom Managed Service Identity endpoint which is automatically determined if not specified. This can also be sourced from the `ARM_MSI_ENDPOINT` environment variable. 221 222 * 223 224 * `subscription_id` - (Optional) The Subscription ID in which the Storage Account exists. This can also be sourced from the `ARM_SUBSCRIPTION_ID` environment variable. 225 226 * `tenant_id` - (Optional) The Tenant ID in which the Subscription exists. This can also be sourced from the `ARM_TENANT_ID` environment variable. 227 228 * `use_microsoft_graph` - (Optional) Should MSAL be used for authentication instead of ADAL, and should Microsoft Graph be used instead of Azure Active Directory Graph? Defaults to `false`. 229 230 -> **Note:** By default the Azure Backend uses ADAL for authentication which is deprecated in favour of MSAL - MSAL can be used by setting `use_microsoft_graph` to `true`. **The default for this will change in Terraform 1.2**, so that MSAL authentication is used by default. 231 232 * `use_msi` - (Optional) Should Managed Service Identity authentication be used? This can also be sourced from the `ARM_USE_MSI` environment variable. 233 234 *** 235 236 When authenticating using a SAS Token associated with the Storage Account - the following fields are also supported: 237 238 * `sas_token` - (Optional) The SAS Token used to access the Blob Storage Account. This can also be sourced from the `ARM_SAS_TOKEN` environment variable. 239 240 *** 241 242 When authenticating using the Storage Account's Access Key - the following fields are also supported: 243 244 * `access_key` - (Optional) The Access Key used to access the Blob Storage Account. This can also be sourced from the `ARM_ACCESS_KEY` environment variable. 245 246 *** 247 248 When authenticating using AzureAD Authentication - the following fields are also supported: 249 250 * `use_azuread_auth` - (Optional) Should AzureAD Authentication be used to access the Blob Storage Account. This can also be sourced from the `ARM_USE_AZUREAD` environment variable. 251 252 -> **Note:** When using AzureAD for Authentication to Storage you also need to ensure the `Storage Blob Data Owner` role is assigned. 253 254 * `use_microsoft_graph` - (Optional) Should MSAL be used for authentication instead of ADAL, and should Microsoft Graph be used instead of Azure Active Directory Graph? Defaults to `false`. 255 256 -> **Note:** By default the Azure Backend uses ADAL for authentication which is deprecated in favour of MSAL - MSAL can be used by setting `use_microsoft_graph` to `true`. **The default for this will change in Terraform 1.2**, so that MSAL authentication is used by default. 257 258 *** 259 260 When authenticating using a Service Principal with a Client Certificate - the following fields are also supported: 261 262 * `resource_group_name` - (Required) The Name of the Resource Group in which the Storage Account exists. 263 264 * `client_id` - (Optional) The Client ID of the Service Principal. This can also be sourced from the `ARM_CLIENT_ID` environment variable. 265 266 * `client_certificate_password` - (Optional) The password associated with the Client Certificate specified in `client_certificate_path`. This can also be sourced from the `ARM_CLIENT_CERTIFICATE_PASSWORD` environment variable. 267 268 * `client_certificate_path` - (Optional) The path to the PFX file used as the Client Certificate when authenticating as a Service Principal. This can also be sourced from the `ARM_CLIENT_CERTIFICATE_PATH` environment variable. 269 270 * `subscription_id` - (Optional) The Subscription ID in which the Storage Account exists. This can also be sourced from the `ARM_SUBSCRIPTION_ID` environment variable. 271 272 * `tenant_id` - (Optional) The Tenant ID in which the Subscription exists. This can also be sourced from the `ARM_TENANT_ID` environment variable. 273 274 * `use_microsoft_graph` - (Optional) Should MSAL be used for authentication instead of ADAL, and should Microsoft Graph be used instead of Azure Active Directory Graph? Defaults to `false`. 275 276 -> **Note:** By default the Azure Backend uses ADAL for authentication which is deprecated in favour of MSAL - MSAL can be used by setting `use_microsoft_graph` to `true`. **The default for this will change in Terraform 1.2**, so that MSAL authentication is used by default. 277 278 *** 279 280 When authenticating using a Service Principal with a Client Secret - the following fields are also supported: 281 282 * `resource_group_name` - (Required) The Name of the Resource Group in which the Storage Account exists. 283 284 * `client_id` - (Optional) The Client ID of the Service Principal. This can also be sourced from the `ARM_CLIENT_ID` environment variable. 285 286 * `client_secret` - (Optional) The Client Secret of the Service Principal. This can also be sourced from the `ARM_CLIENT_SECRET` environment variable. 287 288 * `subscription_id` - (Optional) The Subscription ID in which the Storage Account exists. This can also be sourced from the `ARM_SUBSCRIPTION_ID` environment variable. 289 290 * `tenant_id` - (Optional) The Tenant ID in which the Subscription exists. This can also be sourced from the `ARM_TENANT_ID` environment variable. 291 292 * `use_microsoft_graph` - (Optional) Should MSAL be used for authentication instead of ADAL, and should Microsoft Graph be used instead of Azure Active Directory Graph? Defaults to `false`. 293 294 -> **Note:** By default the Azure Backend uses ADAL for authentication which is deprecated in favour of MSAL - MSAL can be used by setting `use_microsoft_graph` to `true`. **The default for this will change in Terraform 1.2**, so that MSAL authentication is used by default.