1
votes

I had asked this question once before, but realized the answer I got did not fix the entire issue.

In my PowerShell script I have deployed a web app along with Application Insights resources to go along with it (including the Microsoft.Insights/components resource). In another script I am removing these same resources from a Resource Group, but retaining the group name as I am not the only one working in this group.

My issue arises when I try to delete resources. Regardless of the order I choose to do so in, when I execute the command:

Remove-AzureRmResource -ResourceId "/subscriptions/<subscriptionId>/resourceGroups/TestRG/providers/Microsoft.Insights/components/WA-Stag-API-EMEA-zgqmgcwnigknu"

I immediately get the error:

Remove-AzureRmResource : {"code":"Message: {\"Errors\":[\"One of the specified pre-condition is not met\"]}","message":"Message: {\"Errors\":[\"One of the specified pre-condition is not met\"]}\r\nActivityId: 845b19fa-b6b4-4952-9b62-75bfc6e98646, Request URI: /apps/1921ec42-1c88-4fdd-8d6c-78646cba4b15/services/a32b484a-6ee1-4ad7-ab43-4e9 d57bb0b81/partitions/fab8c193-3ec3-45e8-b7a6-0e21d1e071da/replicas/131441657816991616p","innererror":{"diagnosticcontext":"597ea546-7625-474d-b27f-560a1140a652","time":"2017- 07-18T19:41:25.3734216Z"}} At line:1 char:1 + Remove-AzureRmResource -ResourceId "/subscriptions/ ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (:) [Remove-AzureRmResource], ErrorResponseMessageException + FullyQualifiedErrorId : Conflict,Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.RemoveAzureResourceCmdlet

However, if I attempt the same command again, the resource is successfully removed and is no longer visible on the Azure Portal. I would really love to know why this is happening and how to mend the issue that is occurring. The error seems quite long and vague, so I'm at a loss right now on where to even look for a remedy.

EDIT Here's the ARM template I am using to deploy my resources: https://jsonblob.com/1b4ddaa4-6cef-11e7-a38a-2184080e56f4

1
According to the error log, it seems that Insights is used with some resources. When you want to delete Insights, you should unlink them firstly. If possible, could you share your script to create your web app and Insights?Shui shengbao
After you do this template, do you change others? I use your template to deploy in my lab, I don't meet the same error. But when I install Insights extension or Enable client side monitoring. I get the same error log. Also, I test remove web app firstly by using Remove-AzureRmResource -ResourceId "/subscriptions/****-****-****/resourceGroups/shuitest123/providers/Microsoft.Web/sites/WA-QA-CIMS-API-NAA-fo7xm45lirlic" , then delete Insights `Remove-AzureRmResource -ResourceId I don't meet the error log.Shui shengbao
So, I suggest you could check whether the extension is installed. <Your web app>--><Development Tools>--><Extensions>.Shui shengbao
Do you check whether other web app use your Insights. If possible, I suggest you could use dynamic names. I will continue test in my lab and give you the result.Shui shengbao
I test when Insights is linked with other web app, I could not delete it. I still get the error log. If possible, I suggest you could use dynamic Insights name.Shui shengbao

1 Answers

1
votes

When the Insights is used by Web app or other resources, you will get the error log. I check your template, for a development environment, I suggest you don't use same name with your web app and Insights. You had better use a dynamic name for your Insights. It could ensure it is not used by other web app.