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
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
Share Improve this question asked Jan 18 at 13:00 PallabPallab 2,3334 gold badges34 silver badges53 bronze badges 3 |2 Answers
Reset to default 0Before running terraform init
through your current account, you need to authorize in the same command line session:
- Install az command line: https://learn.microsoft/en-us/cli/azure/install-azure-cli
- Run the following command to authorize and set the default session Azure subscription:
az login
Additionally, you may consider using the Shared access key (View account access keys, azurerm-Authentication)
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"
access_key = "..."
}
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
az account list --output table
az account set --subscription <sub name|ID here>"
- Validate Azure credentials are properly set up for Terraform by setting env. variables:
export ARM_SUBSCRIPTION_ID="your-subscription-id"
export ARM_TENANT_ID="your-tenant-id"
export ARM_CLIENT_ID="your-client-id"
export ARM_CLIENT_SECRET="your-client-secret"
- Or if you're using az cli authentication:
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.
Resource group 'rg-terraform-prod-centralus-001' could not be found
- double check the name of the resource group and if you're in the right subscription. – Rui Jarimba Commented Jan 18 at 13:15