hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.6k stars 4.64k forks source link

Creating a Storgae Account with Terraform gives an Error #22494

Closed ashishstationcasinos closed 1 year ago

ashishstationcasinos commented 1 year ago

Is there an existing issue for this?

Community Note

Terraform Version

1.0.10

AzureRM Provider Version

3.59.0

Affected Resource(s)/Data Source(s)

azurerm_storage_account

Terraform Configuration Files

resource "azurerm_resource_group" "rg" {
  name     = "it-${var.cloudEnvironmentAcronym}-${var.regionAcronym}-${var.clusterName}-rg"
  location = var.region

}
resource "azurerm_storage_account" "karbon_storage_account" {
  name                     = "it${var.cloudEnvironmentAcronym}${var.regionAcronym}${var.clusterName}sa"
  resource_group_name      = azurerm_resource_group.rg.name
  location                 = azurerm_resource_group.rg.location
  account_tier             = "Standard"
  account_replication_type = "GRS"

  tags = {
    environment = var.cloudEnvironmentAcronym
  }
  depends_on = [ azurerm_resource_group.rg ]
}
resource "azurerm_storage_container" "karbon_storage_container" {
  name                  = "it${var.cloudEnvironmentAcronym}${var.regionAcronym}${var.clusterName}sc"
  storage_account_name  = azurerm_storage_account.karbon_storage_account.name
  container_access_type = "container"
  depends_on = [ azurerm_storage_account.karbon_storage_account ]
}

Debug Output/Panic Output

terraform plan works fine it says creating a Storage account. But after Apply it fails with below command

reading static website for AzureRM Storage Account "XXXXXXXXX": accounts.Client#GetServiceProperties: Failure responding to request: StatusCode=404 -- Original Error: autorest/azure: Service returned an error. Status=404 Code="ResourceNotFound" Message="The specified resource does not exist.\nRequestId:0edd1499-b01e-0018-1aea-b42975000000\nTime:2023-07-12T18:01:36.4469291Z"
│

Expected Behaviour

Storage account is created and create a container in it.

Actual Behaviour

I see the Storage account created in Portal, But Terraform apply fails with error of "Resource Not Found" for Storage account

reading static website for AzureRM Storage Account "XXXXXXXXXX": accounts.Client#GetServiceProperties: Failure responding to request: StatusCode=404 -- Original Error: autorest/azure: Service returned an error. Status=404 Code="ResourceNotFound" Message="The specified resource does not exist.\nRequestId:0edd1499-b01e-0018-1aea-b42975000000\nTime:2023-07-12T18:01:36.4469291Z" │

Steps to Reproduce

resource "azurerm_resource_group" "rg" { name = "it-${var.cloudEnvironmentAcronym}-${var.regionAcronym}-${var.clusterName}-rg" location = var.region } resource "azurerm_storage_account" "karbon_storage_account" { name = "it${var.cloudEnvironmentAcronym}${var.regionAcronym}${var.clusterName}sa" resource_group_name = azurerm_resource_group.rg.name location = azurerm_resource_group.rg.location account_tier = "Standard" account_replication_type = "GRS"

tags = { environment = var.cloudEnvironmentAcronym } depends_on = [ azurerm_resource_group.rg ] } resource "azurerm_storage_container" "karbon_storage_container" { name = "it${var.cloudEnvironmentAcronym}${var.regionAcronym}${var.clusterName}sc" storage_account_name = azurerm_storage_account.karbon_storage_account.name container_access_type = "container" depends_on = [ azurerm_storage_account.karbon_storage_account ] }

I have azurerm provider confiuration with service princpal id and secret. and Running Terraform in Azure pipelines

Important Factoids

No response

References

No response

magodo commented 1 year ago

@ashishstationcasinos This duplicates to #10872. As is said in https://github.com/hashicorp/terraform-provider-azurerm/issues/10872#issuecomment-1427355983, this error is due to storage data plane resource TTL delay when you are creating a same named resource.

I'm gonna close this issue for now, please , please subscribe #10872 instead.

winterrobert commented 11 months ago

Hey @magodo,

I'm experiencing the same problem. The storage account comes up fine in Azure but Terraform throws:

│ Error: retrieving static website for Storage Account (Subscription: "xxx"
│ Storage Account Name: "xxx"): accounts.Client#GetServiceProperties: Failure responding to request: StatusCode=404 -- Original Error: autorest/azure: Service returned an error. Status=404 Code="ResourceNotFound" Message="The specified resource does not exist.\

#10872 is closed but without a solution to this issue - creating a generic storage account (without any private endpoints) with the same name as one we previously destroyed.

Due to our naming logic in our downstream helm charts, I can't change the name of the storage account. I also need it in Terraform as I use it as an output for creating other resources.

Edit: for info, the same error occurs when trying to import the storage account into Terraform state. Edit2: talked to Azure support, apparently the resources lives on in a deleted state for 14 days after deletion which might cause this issue so after 14 days we should be able to recreate a storage account with the same name?

Is there an open issue somewhere for addressing this?

github-actions[bot] commented 6 months ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.