Skip to content

Terraform 1.11 with azurerm provider Terraform plan fails with 401 authentication issue when backend and azurerm provider are in different tenants #36728

Open
@ctienshi

Description

@ctienshi

Terraform Version

1.11.2

Terraform Configuration Files

  backend "azurerm" {
    subscription_id  = "xxx"
    resource_group_name  = "xxx"
    storage_account_name = "xxx"
    container_name  = "xxx"
    key  = "terraform.tfstate"
    use_azuread_auth     = true
  }
}

# Configure the Azure provider
provider "azurerm" {
  features {}
  subscription_id     = var.subscription_id
  tenant_id               = var.tenant_id
  storage_use_azuread = true
}

Debug Output

│ Error: error loading state: executing request: unexpected status 401 (401 Server failed to authenticate the request. Please refer to the information in the www-authenticate header.) with InvalidAuthenticationInfo: Server failed to authenticate the request. Please refer to the information in the www-authenticate header.
│ RequestId:9b2503f8-501e-0052-2696-99b6f3000000
│ Time:2025-03-20T12:48:14.1906967Z

Expected Behavior

Terraform 1.10.x worked fine.

Actual Behavior

Authentication fails when Terraform plan is run.

│ Error: error loading state: executing request: unexpected status 401 (401 Server failed to authenticate the request. Please refer to the information in the www-authenticate header.) with InvalidAuthenticationInfo: Server failed to authenticate the request. Please refer to the information in the www-authenticate header.
│ RequestId:9b2503f8-501e-0052-2696-99b6f3000000
│ Time:2025-03-20T12:48:14.1906967Z

Steps to Reproduce

terraform init -backend-config=container_name=test
terraform plan

Additional Context

Terraform back is in a storage account in a different Azure tenant. The Azurem provider is configured to deploy the resources in a different Azure tenant. This worked fine with Terraform 1.10.x. After the upgrade to 1.11.2 this starts to fail

References

No response

Generative AI / LLM assisted development?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions