1

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

LillaTheHun
  • 131
  • 1
  • 13
  • 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 Jul 20 '17 at 01:21
  • @Walter-MSFT I added a link to the ARM template that is used to deploy my resources as an edit above. – LillaTheHun Jul 20 '17 at 02:02
  • OK, I will test it in my lab. – Shui shengbao Jul 20 '17 at 02:18
  • 1
    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 Jul 20 '17 at 02:38
  • 1
    So, I suggest you could check whether the extension is installed. `-->-->`. – Shui shengbao Jul 20 '17 at 02:40
  • @Walter-MSFT What if I do not have any extensions installed? I checked after creating the insights and web app, and there werent any present. I then tried to remove the web app: success..... Finally I tried to remove the microsoft.Insights/component resource: failed – LillaTheHun Jul 20 '17 at 17:31
  • 1
    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 Jul 21 '17 at 01:04
  • 1
    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 Jul 21 '17 at 05:58
  • 1
    When the Insights is not linked, I could delete it without any error log. – Shui shengbao Jul 21 '17 at 05:59
  • @Walter-MSFT Sorry for the continued questions! But what do you mean by having a dynamic Insights name and not linking it to another app? Thank you! – LillaTheHun Jul 21 '17 at 10:59
  • 1
    When you create Insights, don't use one same name. – Shui shengbao Jul 21 '17 at 11:26
  • 1
    @Walter-MSFT Can confirm that this method worked! Ensuring the name is different from the web app fixed the issue all together. Thanks! – LillaTheHun Jul 21 '17 at 12:12

1 Answers1

1

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.

Shui shengbao
  • 18,746
  • 3
  • 27
  • 45