I am having the same issue as you are.
In my case I have two azure Service Principals, and the other one is logged out, yet terraform is trying to use the logged out SP to target the resources.
My back end block looks something like this....
terraform {
backend "azurerm" {
subscription_id = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
storage_account_name = "terraformdevstate"
resource_group_name = "cc-dev-rg-tor"
container_name = "tfstate-devops-dev"
key = "dev-test"
}
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~>3.80"
}
azuread = {
source = "hashicorp/azuread"
version = "~>2.4"
}
}
required_version = "~> 1.5"
}
I think terraform is caching and targeting the other subscription even though I am specifically selecting the subscription belonging to the second SP.
Error: Failed to get existing workspaces: Error retrieving keys for Storage Account "terraformdevstate": storage.AccountsClient#ListKeys: Failure responding to request: StatusCode=403 -- Original Error: autorest/azure: Service returned an error. Status=403 Code="AuthorizationFailed" Message="The client '6cb8xxxx-xxxx-xxxx-xxxx-70c35b6cxxxx' with object id '6cb8xxxx-xxxx-xxxx-xxxx-70c35b6cxxxx' does not have authorization to perform action
Even when I logout of the first SP and log into the second SP terraform wants to use the first SP to deploy the infrastructure.
Not sure if this is Terraform or Azure CLI that is at fault here.