cannot find a diagnostic settings resource which terraform states is already present - azure verified modules

rzand 6 Reputation points
2024-08-06T16:51:06.26+00:00

I deployed 3 virtual machines using the azure avm modules.

The code configures the diagnostic settings for the VMs.

I deleted one of the VM from the portal and run the terraform code again.

The code fails stating that the diagnostic setting resource for the deleted and recreated VM already exist. I cannot find that resource. I also tried to remove the whole resource group which should contain the resource. But running the code the error represent itself.

The 3 VMs are configured at the same way using the same version of the avm module.

Error: A resource with the ID "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/rg-xxxxx-xxxxx-uks-001/providers/Microsoft.Compute/virtualMachines/vm-xxxx-sql-01|diag-sql-01" already exists - to be managed via Terraform this resource needs to be imported into the State. Please see the resource documentation for "azurerm_monitor_diagnostic_setting" for more information.

I cannot find the diag-sql-01 resource which anyway should have been removed when I deleted the resource group rg-xxxxx-xxxxx-uks-001

Thank you in advance for your help.

Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
3,212 questions
Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
2,082 questions
Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,811 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.