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.53k stars 4.6k forks source link

Refresh of `azurerm_kusto_database` fails when cluster is stopped state #20633

Open Matthijsy opened 1 year ago

Matthijsy commented 1 year ago

Is there an existing issue for this?

Community Note

Terraform Version

1.3.9

AzureRM Provider Version

3.25

Affected Resource(s)/Data Source(s)

azurerm_kusto_database

Terraform Configuration Files

terraform {
  required_providers {
    azurerm = "~> 3.25"
  }

  required_version = ">= 1.1.0"
}

provider "azurerm" {
  features {}
}

resource "azurerm_resource_group" "main" {
  name     = "rg-adx-test"
  location = "West Europe"
}

resource "azurerm_kusto_cluster" "main" {
  name                = "adxtftest"
  location            = azurerm_resource_group.main.location
  resource_group_name = azurerm_resource_group.main.name
  auto_stop_enabled   = true

  trusted_external_tenants = []
  engine                   = "V3"
  disk_encryption_enabled  = true

  sku {
    name     = "Dev(No SLA)_Standard_E2a_v4"
    capacity = 1
  }
}

resource "azurerm_kusto_database" "database" {
  name                = "database"
  resource_group_name = azurerm_resource_group.main.name
  location            = azurerm_resource_group.main.location

  cluster_name     = azurerm_kusto_cluster.main.name
  hot_cache_period = "P60D"
}

Debug Output/Panic Output

Error: retrieving Database: (Name "database" / Cluster Name "adxtftest" / Resource Group "rg-adx-test"): kusto.DatabasesClient#Get: Failure responding to request: StatusCode=400 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="BadRequest" Message="Cannot fetch databases while resource is in state 'Stopped'."

Expected Behaviour

Either the refresh is skipped, since we cannot read it when the cluster is stopped. Or the cluster is started before refreshing the state. Preferably this is configurable.

Actual Behaviour

When running terraform plan with the ADX cluster in a stopped state, the plan fails.

Steps to Reproduce

  1. Run terraform apply
  2. Shutdown the just created ADX cluster
  3. Run terraform plan

Important Factoids

No response

References

No response

liuwuliuyun commented 1 year ago

Hi @Matthijsy, thanks for raising this issue. Current behavior is by design and not a bug. But we could definitly do better on this. I think skipping the refresh could be a solution. Welcome more discussion on this topic.

Matthijsy commented 1 year ago

Thanks for your response @liuwuliuyun, and sorry for my late response. I understand that it is design by terraform, however it would be great if we could have a workaround/solution for this case. It would be great if we could skip the refresh for just this resource, since I don't want to skip the refresh for all my resources. Are there any existing methods to achieve this? Or could we achieve this within this project?

Would be great to find some solutions for this!

arkoste commented 1 year ago

I'm experiencing the same behaviour. Any workaround/solution?

mockjv commented 7 months ago

Unfortunately, I'm seeing the same. And in our case, we've opted to have a fully replicated Dev, QA, and Production environments. And as a result, the Dev and QA might not see the same kind of utilization and they're almost ALWAYS down when we're trying to perform a terraform update.

While I could easily just add to our GitHub Actions flow to automatically perform a check and a start using the az cli, that's not the most ideal.

ChrisSommers commented 6 months ago

I'm also finding this somewhat annoying...