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.65k forks source link

azurerm_redis_cache errors - async operation failed followed by resource already exists #10340

Open dkirrane opened 3 years ago

dkirrane commented 3 years ago

Community Note

Terraform (and AzureRM Provider) Version

Affected Resource(s)

Terraform Configuration Files

provider "azurerm" {
  features {}
}

resource "random_id" "test" {
  byte_length = 8
}

locals {
  prefix        = "test-${random_id.test.hex}"
  address_space = "10.240.0.0/16"
}

resource "azurerm_resource_group" "this" {
  name     = "${local.prefix}-rg"
  location = "westeurope"
}

resource "azurerm_virtual_network" "this" {
  name                = "${local.prefix}-vnet"
  location            = azurerm_resource_group.this.location
  resource_group_name = azurerm_resource_group.this.name
  address_space       = [local.address_space]
}

resource "azurerm_subnet" "this" {
  name                                           = "redis-subnet"
  resource_group_name                            = azurerm_resource_group.this.name
  virtual_network_name                           = azurerm_virtual_network.this.name
  address_prefixes                               = [cidrsubnet(local.address_space, 6, 4)]
  enforce_private_link_endpoint_network_policies = true
}

resource "azurerm_redis_cache" "this" {
  name                = "${local.prefix}-redis"
  location            = azurerm_resource_group.this.location
  resource_group_name = azurerm_resource_group.this.name
  capacity            = 1
  family              = "P"
  sku_name            = "Premium"
  shard_count         = 1
  enable_non_ssl_port = false
  minimum_tls_version = "1.2"
  subnet_id           = azurerm_subnet.this.id

  redis_configuration {
  }

  timeouts {
    create = "90m"
    update = "90m"
    read   = "5m"
    delete = "90m"
  }
}

Debug Output

azurerm_redis_cache.this: Still creating... [1h10m30s elapsed]

Error: waiting for the create of Redis Cache ... Code="Failed" Message="The async operation failed."

If I try run terraform plan & apply again I hit

Error: A resource with the ID "/subscriptions/..../resourceGroups/.../providers/Microsoft.Cache/Redis/my-redis" already exists - to be managed via Terraform this resource needs to be imported into the State. Please see the resource documentation for "azurerm_redis_cache" for more information.

Expected Behaviour

azurerm_redis_cache should not fail if Redis does end up getting created.

Actual Behaviour

azurerm_redis_cache fails. But I can see in the Azure portal that Redis goes on and gets created successfully.

Steps to Reproduce

terraform apply

placyd commented 3 years ago

The same here. Without setting virtual network configuriation works.

dkirrane commented 3 years ago

Still hitting this on Terraform v0.14.9

    azurerm = {
      source = "hashicorp/azurerm"
      version = "2.56.0"
    }
kyoshiro commented 3 years ago

Problem still exists with:

azurerm = {
  version = "~> 2.64"
  source  = "hashicorp/azurerm"
}
dzmitry-lahoda commented 2 years ago

I observe Debug Output as described while creating redis similar to above, but without subnetwork applied. I check manually azure portal and see redis is created here. but terraform does not see it. so i do other settings, these can have some influence

dzmitry-lahoda commented 2 years ago

issue may be related to https://github.com/hashicorp/terraform-provider-azurerm/pull/14208 about getting wrong redis id path, so not tested

DesislavaNPetrova commented 1 year ago

Problem still exist with:

azurerm = { version = "~> 3.6.0" source = "hashicorp/azurerm" }