最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

azure - Getting Error while trying to do Terraform Init - Stack Overflow

programmeradmin2浏览0评论

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
  • 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
  • This question is similar to: 'terraform init' returns 404 'Resource Group not found' when it does exist. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem. – Rui Jarimba Commented Jan 18 at 13:16
  • See also stackoverflow/questions/53418223/… – Rui Jarimba Commented Jan 18 at 13:17
Add a comment  | 

2 Answers 2

Reset to default 0

Before running terraform init through your current account, you need to authorize in the same command line session:

  1. Install az command line: https://learn.microsoft/en-us/cli/azure/install-azure-cli
  2. 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:

  1. Verify the authenticated Azure subscription in your terminal: az account show

  2. 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>"
  1. 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
  1. Verify the resource group exists in your current subscription: az group show --name rg-terraform-prod-centralus-001

  2. 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.

发布评论

评论列表(0)

  1. 暂无评论