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

Resources created by an Application Insights instance are not managed nor deleted by terraform #18375

Open eduardoriveror opened 2 years ago

eduardoriveror commented 2 years ago

I have followed the case #16124 but I am still facing the same issue with the latest version of the provider.

Process:

  1. Run terraform apply
  2. fails after one hour with a timeout trying to create the Application Insights instance
  3. In the Azure Console, the Application Insights is created and no Smart Detection rule is created
  4. Trying to plan again shows that the application insights instance needs to be created
  5. Applying again fails because a resource with the same id is already created
  6. To be able to destroy, manual deletion of the application insights instance is needed
  7. Only way to work is forcing the deletion of resource groups when there are still existing resources

Is there an existing issue for this?

Community Note

Terraform Version

1.2.5

AzureRM Provider Version

8.22.0

Affected Resource(s)/Data Source(s)

azurerm_application_insights

Terraform Configuration Files

terraform {
  required_version = "1.2.5"
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "3.22.0"
    }
  }
  backend "azurerm" {
  }
}

provider "azurerm" {
  features {
    application_insights {
      disable_generated_rule = true
    }
  }
}
resource "azurerm_application_insights" "appi" {
  name                = "appi-1"
  location            = var.location
  resource_group_name = var.resource_group_name
  workspace_id        = var.log_analytics_workspace_id
  application_type    = var.application_type
  retention_in_days   = var.retention_in_days
}

Debug Output/Panic Output

module.xxxx.module.xxxx.azurerm_application_insights.backend_appi: Still creating... [10m51s elapsed]
module.xxxx.module.xxxx.azurerm_application_insights.backend_appi: Still creating... [11m1s elapsed]
module.xxxx.module.xxx.azurerm_application_insights.backend_appi: Still creating... [11m11s elapsed]
...
Crashing after 1hr

Expected Behaviour

module.xxxx.module.xxxx.azurerm_application_insights.backend_appi: Still creating... [10m51s elapsed] module.xxxx.module.xxxx.azurerm_application_insights.backend_appi: Still creating... [11m1s elapsed] module.xxxx.module.xxx.azurerm_application_insights.backend_appi: Still creating... [11m11s elapsed]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

Actual Behaviour

module.xxxx.module.xxxx.azurerm_application_insights.backend_appi: Still creating... [10m51s elapsed] module.xxxx.module.xxxx.azurerm_application_insights.backend_appi: Still creating... [11m1s elapsed] module.xxxx.module.xxx.azurerm_application_insights.backend_appi: Still creating... [11m11s elapsed] ... Crashing after 1hr

Steps to Reproduce

No response

Important Factoids

No response

References

15892

16124

thedevopsjedi commented 2 weeks ago

I recently had this exact issue and was able to repeat it multiple times. It turned out to be caused by a failed deployment in the resource group as the 'Microsoft.AlertsManagement" provider hadn't been registered. I registered the provider using the block below and the issue went away.

resource "azurerm_resource_provider_registration" "microsoft_alertsmanagement" { name = "Microsoft.AlertsManagement" }

I'd say this issue can be closed.