diff --git a/.changes/v1.13/ENHANCEMENTS-20250425-160021.yaml b/.changes/v1.13/ENHANCEMENTS-20250425-160021.yaml new file mode 100644 index 000000000000..d7e7c3e74204 --- /dev/null +++ b/.changes/v1.13/ENHANCEMENTS-20250425-160021.yaml @@ -0,0 +1,5 @@ +kind: ENHANCEMENTS +body: 'backend/azurerm: Support Azure DevOps environment variables and backend specific variables' +time: 2025-04-25T16:00:21.8153592+01:00 +custom: + Issue: "36922" diff --git a/internal/backend/remote-state/azure/backend.go b/internal/backend/remote-state/azure/backend.go index d82e172101ba..4c273312ce90 100644 --- a/internal/backend/remote-state/azure/backend.go +++ b/internal/backend/remote-state/azure/backend.go @@ -102,7 +102,7 @@ func New() backend.Backend { Type: schema.TypeString, Optional: true, Description: "The Client ID to use when authenticating using Azure Active Directory.", - DefaultFunc: schema.EnvDefaultFunc("ARM_CLIENT_ID", ""), + DefaultFunc: schema.MultiEnvDefaultFunc([]string{"ARM_CLIENT_ID_BACKEND", "ARM_CLIENT_ID"}, ""), }, "client_id_file_path": { @@ -166,7 +166,7 @@ func New() backend.Backend { "ado_pipeline_service_connection_id": { Type: schema.TypeString, Optional: true, - DefaultFunc: schema.MultiEnvDefaultFunc([]string{"ARM_ADO_PIPELINE_SERVICE_CONNECTION_ID", "ARM_OIDC_AZURE_SERVICE_CONNECTION_ID"}, nil), + DefaultFunc: schema.MultiEnvDefaultFunc([]string{"ARM_OIDC_AZURE_SERVICE_CONNECTION_ID_BACKEND", "ARM_ADO_PIPELINE_SERVICE_CONNECTION_ID", "ARM_OIDC_AZURE_SERVICE_CONNECTION_ID", "AZURESUBSCRIPTION_SERVICE_CONNECTION_ID"}, nil), Description: "The Azure DevOps Pipeline Service Connection ID.", }, diff --git a/website/docs/language/backend/azurerm.mdx b/website/docs/language/backend/azurerm.mdx index 6237ed3f618e..c6e22242525f 100644 --- a/website/docs/language/backend/azurerm.mdx +++ b/website/docs/language/backend/azurerm.mdx @@ -70,7 +70,7 @@ These optional configuration options apply when [looking up the data plane URI]( The recommended data plane role assignments required for this method are either one of: -- `Storage Blob Data Owner` on the storage account container (Recommended) +- `Storage Blob Data Contributor` on the storage account container (Recommended) - `Storage Blob Data Contributor` on the storage account The recommended management plane role assignments required for this method are: @@ -106,19 +106,19 @@ terraform { #### Example Configuration for Azure DevOps -With Azure DevOps, the ID Token endpoint environment variables are automatically found, but you need to supply the service connection ID in `oidc_azure_service_connection_id`. If you are using the `AzureCLI` or `AzurePowerShell` tasks, the service connection ID is automatically set to the `AZURESUBSCRIPTION_SERVICE_CONNECTION_ID` environment variable. +With Azure DevOps, the ID Token endpoint environment variables are automatically found, but you need to supply the service connection ID in `ado_pipeline_service_connection_id`. If you are using the `AzureCLI` or `AzurePowerShell` tasks, the service connection ID is automatically set to the `AZURESUBSCRIPTION_SERVICE_CONNECTION_ID` environment variable. ```hcl terraform { backend "azurerm" { - use_oidc = true # Can also be set via `ARM_USE_OIDC` environment variable. - oidc_azure_service_connection_id = "00000000-0000-0000-0000-000000000000" # Can also be set via `ARM_OIDC_AZURE_SERVICE_CONNECTION_ID` environment variable. - use_azuread_auth = true # Can also be set via `ARM_USE_AZUREAD` environment variable. - tenant_id = "00000000-0000-0000-0000-000000000000" # Can also be set via `ARM_TENANT_ID` environment variable. - client_id = "00000000-0000-0000-0000-000000000000" # Can also be set via `ARM_CLIENT_ID` environment variable. - storage_account_name = "abcd1234" # Can be passed via `-backend-config=`"storage_account_name="` in the `init` command. - container_name = "tfstate" # Can be passed via `-backend-config=`"container_name="` in the `init` command. - key = "prod.terraform.tfstate" # Can be passed via `-backend-config=`"key="` in the `init` command. + use_oidc = true # Can also be set via `ARM_USE_OIDC` environment variable. + ado_pipeline_service_connection_id = "00000000-0000-0000-0000-000000000000" # Can also be set via `ARM_OIDC_AZURE_SERVICE_CONNECTION_ID` environment variable. + use_azuread_auth = true # Can also be set via `ARM_USE_AZUREAD` environment variable. + tenant_id = "00000000-0000-0000-0000-000000000000" # Can also be set via `ARM_TENANT_ID` environment variable. + client_id = "00000000-0000-0000-0000-000000000000" # Can also be set via `ARM_CLIENT_ID` environment variable. + storage_account_name = "abcd1234" # Can be passed via `-backend-config=`"storage_account_name="` in the `init` command. + container_name = "tfstate" # Can be passed via `-backend-config=`"container_name="` in the `init` command. + key = "prod.terraform.tfstate" # Can be passed via `-backend-config=`"key="` in the `init` command. } } ``` @@ -339,7 +339,7 @@ These optional configuration options apply when [looking up the data plane URI]( The recommended data plane role assignments required for this method are either one of: -- `Storage Blob Data Owner` on the storage account container (Recommended) +- `Storage Blob Data Contributor` on the storage account container (Recommended) - `Storage Blob Data Contributor` on the storage account The recommended management plane role assignments required for this method are: @@ -379,20 +379,20 @@ terraform { #### Example Configuration for Azure DevOps -With Azure DevOps, the ID Token endpoint environment variables are automatically found, but you need to supply the service connection ID in `oidc_azure_service_connection_id`. If you are using the `AzureCLI` or `AzurePowerShell` tasks, the service connection ID is automatically set to the `AZURESUBSCRIPTION_SERVICE_CONNECTION_ID` environment variable. +With Azure DevOps, the ID Token endpoint environment variables are automatically found, but you need to supply the service connection ID in `ado_pipeline_service_connection_id`. If you are using the `AzureCLI` or `AzurePowerShell` tasks, the service connection ID is automatically set to the `AZURESUBSCRIPTION_SERVICE_CONNECTION_ID` environment variable. ```hcl terraform { backend "azurerm" { - use_oidc = true # Can also be set via `ARM_USE_OIDC` environment variable. - oidc_azure_service_connection_id = "00000000-0000-0000-0000-000000000000" # Can also be set via `ARM_OIDC_AZURE_SERVICE_CONNECTION_ID` environment variable. - tenant_id = "00000000-0000-0000-0000-000000000000" # Can also be set via `ARM_TENANT_ID` environment variable. - subscription_id = "00000000-0000-0000-0000-000000000000" # Can also be set via `ARM_SUBSCRIPTION_ID` environment variable. - client_id = "00000000-0000-0000-0000-000000000000" # Can also be set via `ARM_CLIENT_ID` environment variable. - resource_group_name = "StorageAccount-ResourceGroup" # Can be passed via `-backend-config=`"resource_group_name="` in the `init` command. - storage_account_name = "abcd1234" # Can be passed via `-backend-config=`"storage_account_name="` in the `init` command. - container_name = "tfstate" # Can be passed via `-backend-config=`"container_name="` in the `init` command. - key = "prod.terraform.tfstate" # Can be passed via `-backend-config=`"key="` in the `init` command. + use_oidc = true # Can also be set via `ARM_USE_OIDC` environment variable. + ado_pipeline_service_connection_id = "00000000-0000-0000-0000-000000000000" # Can also be set via `ARM_OIDC_AZURE_SERVICE_CONNECTION_ID` environment variable. + tenant_id = "00000000-0000-0000-0000-000000000000" # Can also be set via `ARM_TENANT_ID` environment variable. + subscription_id = "00000000-0000-0000-0000-000000000000" # Can also be set via `ARM_SUBSCRIPTION_ID` environment variable. + client_id = "00000000-0000-0000-0000-000000000000" # Can also be set via `ARM_CLIENT_ID` environment variable. + resource_group_name = "StorageAccount-ResourceGroup" # Can be passed via `-backend-config=`"resource_group_name="` in the `init` command. + storage_account_name = "abcd1234" # Can be passed via `-backend-config=`"storage_account_name="` in the `init` command. + container_name = "tfstate" # Can be passed via `-backend-config=`"container_name="` in the `init` command. + key = "prod.terraform.tfstate" # Can be passed via `-backend-config=`"key="` in the `init` command. } } ``` @@ -548,9 +548,9 @@ The following configuration options are supported: * `use_oidc` - (Optional) Set to `true` to use OpenID Connect / Workload identity federation authentication for authentication to the storage account management and data plane. This can also be sourced from the `ARM_USE_OIDC` environment variable. -* `client_id` - (Optional) The Client ID of the Azure Active Directory Principal required for some authentication sub-types. This can also be sourced from the `ARM_CLIENT_ID` environment variable. +* `client_id` - (Optional) The Client ID of the Azure Active Directory Principal required for some authentication sub-types. This can also be sourced from the `ARM_CLIENT_ID` or `ARM_CLIENT_ID_BACKEND` environment variable. -* `ado_pipeline_service_connection_id` - (Optional) The Azure DevOps Pipeline Service Connection ID required for Open ID Connect / Workload identity federation authentication with Azure DevOps. This can also be sourced from the `ARM_ADO_PIPELINE_SERVICE_CONNECTION_ID` or `ARM_OIDC_AZURE_SERVICE_CONNECTION_ID` environment variables. The provider will look for values in this order and use the first it finds configured. +* `ado_pipeline_service_connection_id` - (Optional) The Azure DevOps Pipeline Service Connection ID required for Open ID Connect / Workload identity federation authentication with Azure DevOps. This can also be sourced from the `ARM_OIDC_AZURE_SERVICE_CONNECTION_ID`, `ARM_OIDC_PIPELIME_SERVICE_CONNECTION_ID`, `AZURESUBSCRIPTION_SERVICE_CONNECTION_ID` or `ARM_OIDC_AZURE_SERVICE_CONNECTION_ID_BACKEND` environment variables. The provider will look for values in this order and use the first it finds configured. * `oidc_request_url` - (Optional) The URL for the Open ID Connect provider from which to request an ID token. This is only required for advanced scenarios or third party integrations. This can also be sourced from the `ARM_OIDC_REQUEST_URL`, `ACTIONS_ID_TOKEN_REQUEST_URL` or `SYSTEM_OIDCREQUESTURI` environment variables. The provider will look for values in this order and use the first it finds configured.