I am trying to do Terraform init and i am getting the below error
│ Error: Failed to get existing workspaces: Error retrieving keys for Storage Account "stmpltfstateprdcus001": storage.AccountsClient#ListKeys: Failure responding to request: StatusCode=404 -- Original Error: autorest/azure: Service returned an error. Status=404 Code="ResourceGroupNotFound" Message="Resource group 'rg-terraform-prod-centralus-001' could not be found."
This is my backend configuration :
terraform {
required_version = "~> 1.0"
required_providers {
azuread = "~> 3.0"
azurerm = "~> 4.0"
}
backend "azurerm" {
resource_group_name = "rg-terraform-prod-centralus-001"
storage_account_name = "stmpltfstateprdcus001"
container_name = "terraform"
key = "mg-PLATFORM-repo-Azure_Lz_Core-branch-main-template-platform_landing_zone.tfstate"
}
}
I am logged in to Azure with my account and i can see the Storage Account Access Keys. I have full access
So what is the issue here
2
Answers
Before running
terraform init
through your current account, you need to authorize in the same command line session:az login
Additionally, you may consider using the Shared access key (View account access keys, azurerm-Authentication)
If you can see the Storage Account in Azure but Terraform is giving a
404
error for the resource group, then check:Verify the authenticated Azure subscription in your terminal:
az account show
If the subscription context is incorrect, list available subs and change the context
export ARM_USE_CLI=true
Verify the resource group exists in your current subscription:
az group show --name rg-terraform-prod-centralus-001
Check storage account accessibility:
az storage account show --name stmpltfstateprdcus001 --resource-group rg-terraform-prod-centralus-001
It’s likely that there is a mismatch between the subscription you’re authenticated to and the subscription containing the backend resources.