Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3.0.1: Cannot destroy eventhub namespace due to the error "The Resource Group still contains Resources" #16069

Closed
F-Joachim opened this issue Mar 25, 2022 · 4 comments · Fixed by #16073

Comments

@F-Joachim
Copy link

F-Joachim commented Mar 25, 2022

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform (and AzureRM Provider) Version

$ terraform -v
Terraform v1.1.7
on linux_amd64

Providers:

  • hashicorp/azurerm => 3.0.1

Affected Resource(s)

  • azurerm_eventhub_namespace

Terraform Configuration Files

terraform {
   backend "azurerm" {}
}

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "3.0.1"
    }
  }
}

provider "azurerm" {
  features {}
}

resource "azurerm_resource_group" "example" {
  name     = "test-462912"
  location = "West Europe"
}

resource "azurerm_eventhub_namespace" "example" {
  name                = "eventhub-ns"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
  sku                 = "Standard"
  capacity            = 1

  tags = {
    environment = "Production"
  }
}

resource "azurerm_eventhub" "example" {
  name                = "eventhub"
  namespace_name      = azurerm_eventhub_namespace.example.name
  resource_group_name = azurerm_resource_group.example.name
  partition_count     = 2
  message_retention   = 1
}

Debug Output

-

Panic Output

-

Expected Behaviour

All resources should be successfully destroyed.

...
azurerm_eventhub_namespace.example: Destroying... [id=/subscriptions/<subscription-id>/resourceGroups/test-462912/providers/Microsoft.EventHub/namespaces/eventhub-ns]
azurerm_eventhub_namespace.example: Still destroying... [id=/subscriptions/<subscription-id>-...EventHub/namespaces/eventhub-ns, 10s elapsed]
azurerm_eventhub_namespace.example: Still destroying... [id=/subscriptions/<subscription-id>-...EventHub/namespaces/eventhub-ns, 20s elapsed]
azurerm_eventhub_namespace.example: Still destroying... [id=/subscriptions/<subscription-id>-...EventHub/namespaces/eventhub-ns, 30s elapsed]
azurerm_eventhub_namespace.example: Still destroying... [id=/subscriptions/<subscription-id>-...EventHub/namespaces/eventhub-ns, 40s elapsed]
azurerm_eventhub_namespace.example: Still destroying... [id=/subscriptions/<subscription-id>-...EventHub/namespaces/eventhub-ns, 50s elapsed]
azurerm_eventhub_namespace.example: Destruction complete after 50s
...
azurerm_resource_group.example: Destruction complete after 1m21s

Destroy complete! Resources: 3 destroyed.

Actual Behaviour

The resource_group cannot be deleted because Terraform has detected that the eventhub_namespace still exists, even though it was successfully deleted according to the log:

azurerm_eventhub_namespace.example: Still destroying... [id=/subscriptions/<subscription-id>-...EventHub/namespaces/eventhub-ns, 20s elapsed]
azurerm_eventhub_namespace.example: Still destroying... [id=/subscriptions/<subscription-id>-...EventHub/namespaces/eventhub-ns, 30s elapsed]
azurerm_eventhub_namespace.example: Destruction complete after 32s
azurerm_resource_group.example: Destroying... [id=/subscriptions/<subscription-id>/resourceGroups/test-462912]
╷
│ Error: deleting Resource Group "test-462912": the Resource Group still contains Resources.
│ 
│ Terraform is configured to check for Resources within the Resource Group when deleting the Resource Group - and
│ raise an error if nested Resources still exist to avoid unintentionally deleting these Resources.
│ 
│ Terraform has detected that the following Resources still exist within the Resource Group:
│ 
│ * `/subscriptions/<subscription-id>/resourceGroups/test-462912/providers/Microsoft.EventHub/namespaces/eventhub-ns`
│ 
│ This feature is intended to avoid the unintentional destruction of nested Resources provisioned through some
│ other means (for example, an ARM Template Deployment) - as such you must either remove these Resources, or
│ disable this behaviour using the feature flag `prevent_deletion_if_contains_resources` within the `features`
│ block when configuring the Provider, for example:
│ 
│ provider "azurerm" {
│   features {
│     resource_group {
│       prevent_deletion_if_contains_resources = false
│     }
│   }
│ }
│ 
│ When that feature flag is set, Terraform will skip checking for any Resources within the Resource Group and
│ delete this using the Azure API directly (which will clear up any nested resources).
│ 
│ More information on the `features` block can be found in the documentation:
│ https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs#features
│ 
│ 
│ 
╵

Steps to Reproduce

  1. terraform init
  2. terraform apply
  3. terraform destroy

Important Factoids

References

  • #0000
@katbyte
Copy link
Collaborator

katbyte commented Mar 25, 2022

Hey @F-Joachim - thanks for letting us know about this bug. Looks like there can be some eventually consistency issues with this check, especially with certain services. we've open #16073 that adds some retries to give azure time to settle so hopefully that will resolve this for you!

should go out with 3.0.2 later today 🙂

@katbyte katbyte added this to the v3.0.2 milestone Mar 25, 2022
@github-actions
Copy link

This functionality has been released in v3.0.2 of the Terraform Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@F-Joachim
Copy link
Author

@katbyte - Thanks for your quick reply. The version v3.0.2 fixes the problem described above 👍

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
2 participants