github.com/eliastor/durgaform@v0.0.0-20220816172711-d0ab2d17673e/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  ~> **Terraform 1.1 and 1.2 supported a feature-flag to allow enabling/disabling the use of Microsoft Graph (and MSAL) rather than Azure Active Directory Graph (and ADAL) - however this flag has since been removed in Terraform 1.3. Microsoft Graph (and MSAL) are now enabled by default and Azure Active Directory Graph (and ADAL) can no longer be used.
    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 OpenID Connect (OIDC):
    50  
    51  ```hcl
    52  terraform {
    53    backend "azurerm" {
    54      resource_group_name  = "StorageAccount-ResourceGroup"
    55      storage_account_name = "abcd1234"
    56      container_name       = "tfstate"
    57      key                  = "prod.terraform.tfstate"
    58      use_oidc             = true
    59      subscription_id      = "00000000-0000-0000-0000-000000000000"
    60      tenant_id            = "00000000-0000-0000-0000-000000000000"
    61    }
    62  }
    63  ```
    64  
    65  ***
    66  
    67  When authenticating using Azure AD Authentication:
    68  
    69  ```hcl
    70  terraform {
    71    backend "azurerm" {
    72      storage_account_name = "abcd1234"
    73      container_name       = "tfstate"
    74      key                  = "prod.terraform.tfstate"
    75      use_azuread_auth     = true
    76      subscription_id      = "00000000-0000-0000-0000-000000000000"
    77      tenant_id            = "00000000-0000-0000-0000-000000000000"
    78    }
    79  }
    80  ```
    81  
    82  -> **Note:** When using AzureAD for Authentication to Storage you also need to ensure the `Storage Blob Data Owner` role is assigned.
    83  
    84  ***
    85  
    86  When authenticating using the Access Key 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 Access Key can also be sourced
    96      # from an Environment Variable - more information is available below.
    97      access_key = "abcdefghijklmnopqrstuvwxyz0123456789..."
    98    }
    99  }
   100  ```
   101  
   102  ***
   103  
   104  When authenticating using a SAS Token associated with the Storage Account:
   105  
   106  ```hcl
   107  terraform {
   108    backend "azurerm" {
   109      storage_account_name = "abcd1234"
   110      container_name       = "tfstate"
   111      key                  = "prod.terraform.tfstate"
   112  
   113      # rather than defining this inline, the SAS Token can also be sourced
   114      # from an Environment Variable - more information is available below.
   115      sas_token = "abcdefghijklmnopqrstuvwxyz0123456789..."
   116    }
   117  }
   118  ```
   119  
   120  -> **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.
   121  
   122  ## Data Source Configuration
   123  
   124  When authenticating using a Service Principal (either with a Client Certificate or a Client Secret):
   125  
   126  ```hcl
   127  data "terraform_remote_state" "foo" {
   128    backend = "azurerm"
   129    config = {
   130      storage_account_name = "terraform123abc"
   131      container_name       = "terraform-state"
   132      key                  = "prod.terraform.tfstate"
   133    }
   134  }
   135  ```
   136  
   137  ***
   138  
   139  When authenticating using Managed Service Identity (MSI):
   140  
   141  ```hcl
   142  data "terraform_remote_state" "foo" {
   143    backend = "azurerm"
   144    config = {
   145      resource_group_name  = "StorageAccount-ResourceGroup"
   146      storage_account_name = "terraform123abc"
   147      container_name       = "terraform-state"
   148      key                  = "prod.terraform.tfstate"
   149      use_msi              = true
   150      subscription_id      = "00000000-0000-0000-0000-000000000000"
   151      tenant_id            = "00000000-0000-0000-0000-000000000000"
   152    }
   153  }
   154  ```
   155  
   156  ***
   157  
   158  When authenticating using OpenID Connect (OIDC):
   159  
   160  ```hcl
   161  data "terraform_remote_state" "foo" {
   162    backend = "azurerm"
   163    config = {
   164      resource_group_name  = "StorageAccount-ResourceGroup"
   165      storage_account_name = "terraform123abc"
   166      container_name       = "terraform-state"
   167      key                  = "prod.terraform.tfstate"
   168      use_oidc             = true
   169      subscription_id      = "00000000-0000-0000-0000-000000000000"
   170      tenant_id            = "00000000-0000-0000-0000-000000000000"
   171    }
   172  }
   173  ```
   174  
   175  ***
   176  
   177  When authenticating using AzureAD Authentication:
   178  
   179  ```hcl
   180  data "terraform_remote_state" "foo" {
   181    backend = "azurerm"
   182    config = {
   183      storage_account_name = "terraform123abc"
   184      container_name       = "terraform-state"
   185      key                  = "prod.terraform.tfstate"
   186      use_azuread_auth     = true
   187      subscription_id      = "00000000-0000-0000-0000-000000000000"
   188      tenant_id            = "00000000-0000-0000-0000-000000000000"
   189    }
   190  }
   191  ```
   192  
   193  -> **Note:** When using AzureAD for Authentication to Storage you also need to ensure the `Storage Blob Data Owner` role is assigned.
   194  
   195  ***
   196  
   197  When authenticating using the Access Key associated with the Storage Account:
   198  
   199  ```hcl
   200  data "terraform_remote_state" "foo" {
   201    backend = "azurerm"
   202    config = {
   203      storage_account_name = "terraform123abc"
   204      container_name       = "terraform-state"
   205      key                  = "prod.terraform.tfstate"
   206  
   207      # rather than defining this inline, the Access Key can also be sourced
   208      # from an Environment Variable - more information is available below.
   209      access_key = "abcdefghijklmnopqrstuvwxyz0123456789..."
   210    }
   211  }
   212  ```
   213  
   214  ***
   215  
   216  When authenticating using a SAS Token associated with the Storage Account:
   217  
   218  ```hcl
   219  data "terraform_remote_state" "foo" {
   220    backend = "azurerm"
   221    config = {
   222      storage_account_name = "terraform123abc"
   223      container_name       = "terraform-state"
   224      key                  = "prod.terraform.tfstate"
   225  
   226      # rather than defining this inline, the SAS Token can also be sourced
   227      # from an Environment Variable - more information is available below.
   228      sas_token = "abcdefghijklmnopqrstuvwxyz0123456789..."
   229    }
   230  }
   231  ```
   232  
   233  ## Configuration Variables
   234  
   235  !> **Warning:**  We recommend using environment variables to supply credentials and other sensitive data. If you use `-backend-config` or hardcode these values directly in your configuration, Terraform will include these values in both the `.terraform` subdirectory and in plan files. Refer to [Credentials and Sensitive Data](/language/settings/backends/configuration#credentials-and-sensitive-data) for details.
   236  
   237  
   238  The following configuration options are supported:
   239  
   240  * `storage_account_name` - (Required) The Name of [the Storage Account](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/storage_account).
   241  
   242  * `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.
   243  
   244  * `key` - (Required) The name of the Blob used to retrieve/store Terraform's State file inside the Storage Container.
   245  
   246  * `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`.
   247  
   248  * `endpoint` - (Optional) The Custom Endpoint for Azure Resource Manager. This can also be sourced from the `ARM_ENDPOINT` environment variable.
   249  
   250  ~> **NOTE:** An `endpoint` should only be configured when using Azure Stack.
   251  
   252  * `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.
   253  
   254  ***
   255  
   256  When authenticating using the Managed Service Identity (MSI) - the following fields are also supported:
   257  
   258  * `resource_group_name` - (Required) The Name of the Resource Group in which the Storage Account exists.
   259  
   260  * `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.
   261  
   262  * `subscription_id` - (Optional) The Subscription ID in which the Storage Account exists. This can also be sourced from the `ARM_SUBSCRIPTION_ID` environment variable.
   263  
   264  * `tenant_id` - (Optional) The Tenant ID in which the Subscription exists. This can also be sourced from the `ARM_TENANT_ID` environment variable.
   265  
   266  * `use_msi` - (Optional) Should Managed Service Identity authentication be used? This can also be sourced from the `ARM_USE_MSI` environment variable.
   267  
   268  ***
   269  
   270  When authenticating using a Service Principal with OpenID Connect (OIDC) - the following fields are also supported:
   271  
   272  * `oidc_request_url` - (Optional) The URL for the OIDC provider from which to request an ID token. This can also be sourced from the `ARM_OIDC_REQUEST_URL` or `ACTIONS_ID_TOKEN_REQUEST_URL` environment variables.
   273  
   274  * `oidc_request_token` - (Optional) The bearer token for the request to the OIDC provider. This can also be sourced from the `ARM_OIDC_REQUEST_TOKEN` or `ACTIONS_ID_TOKEN_REQUEST_TOKEN` environment variables.
   275  
   276  * `use_oidc` - (Optional) Should OIDC authentication be used? This can also be sourced from the `ARM_USE_OIDC` environment variable.
   277  
   278  ***
   279  
   280  When authenticating using a SAS Token associated with the Storage Account - the following fields are also supported:
   281  
   282  * `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.
   283  
   284  ***
   285  
   286  When authenticating using the Storage Account's Access Key - the following fields are also supported:
   287  
   288  * `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.
   289  
   290  ***
   291  
   292  When authenticating using AzureAD Authentication - the following fields are also supported:
   293  
   294  * `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.
   295  
   296  -> **Note:** When using AzureAD for Authentication to Storage you also need to ensure the `Storage Blob Data Owner` role is assigned.
   297  
   298  ***
   299  
   300  When authenticating using a Service Principal with a Client Certificate - the following fields are also supported:
   301  
   302  * `resource_group_name` - (Required) The Name of the Resource Group in which the Storage Account exists.
   303  
   304  * `client_id` - (Optional) The Client ID of the Service Principal. This can also be sourced from the `ARM_CLIENT_ID` environment variable.
   305  
   306  * `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.
   307  
   308  * `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.
   309  
   310  * `subscription_id` - (Optional) The Subscription ID in which the Storage Account exists. This can also be sourced from the `ARM_SUBSCRIPTION_ID` environment variable.
   311  
   312  * `tenant_id` - (Optional) The Tenant ID in which the Subscription exists. This can also be sourced from the `ARM_TENANT_ID` environment variable.
   313  
   314  ***
   315  
   316  When authenticating using a Service Principal with a Client Secret - the following fields are also supported:
   317  
   318  * `resource_group_name` - (Required) The Name of the Resource Group in which the Storage Account exists.
   319  
   320  * `client_id` - (Optional) The Client ID of the Service Principal. This can also be sourced from the `ARM_CLIENT_ID` environment variable.
   321  
   322  * `client_secret` - (Optional) The Client Secret of the Service Principal. This can also be sourced from the `ARM_CLIENT_SECRET` environment variable.
   323  
   324  * `subscription_id` - (Optional) The Subscription ID in which the Storage Account exists. This can also be sourced from the `ARM_SUBSCRIPTION_ID` environment variable.
   325  
   326  * `tenant_id` - (Optional) The Tenant ID in which the Subscription exists. This can also be sourced from the `ARM_TENANT_ID` environment variable.