Alert creation for AppInsights fails with “Code”:“ResourceNotSupported”

前端 未结 2 402
星月不相逢
星月不相逢 2021-01-23 14:41

I created an App Insights in Central US region using this script:

New-AzureRmResource -ResourceName $appInsightsName -ResourceGroupName $defaultRgName -Tag @{ Na         


        
2条回答
  •  情歌与酒
    2021-01-23 15:31

    Azure Resources are not all available in every region or cloud type. So you will have to check before you build out your templates or execute PS create/move resource scripts.

    Powershell command for checking the availability region of a resource:

    $resources = Get-AzureRmResourceProvider -ProviderNamespace Microsoft.Insights -ApiVersion "2015-05-01"
    $resources.ResourceTypes.Where{($_.ResourceTypeName -eq 'components')}.Locations
    

    You'll notice that I used the ApiVersion flag. This is going to be required since some resources are only available in regions with their newer APIs.

    Because I had this same issue when deploying my ARM Templates, I needed to makes sure that my deployable region list did not include invalid values. So I generated a list of valid regions that I can deploy the following.

    • Microsoft.Insights/components
    • Microsoft.Insights/webtests
    • microsoft.insights/alertrules

    Here is the Powershell I generated my list with. I am targeting the 2015-05-01 API as of this post.

    $resources = Get-AzureRmResourceProvider -ProviderNamespace Microsoft.Insights -ApiVersion "2015-05-01"
    $components = $resources.ResourceTypes.Where{($_.ResourceTypeName -eq 'components')}.Locations
    $webtests = $resources.ResourceTypes.Where{($_.ResourceTypeName -eq 'webtests')}.Locations
    $alertrules = $resources.ResourceTypes.Where{($_.ResourceTypeName -eq 'alertrules')}.Locations
    

    $components | ?{ $webtests -contains $_ } | ?{ $alertrules -contains $_ }

    And the resulting list is:

    East US
    South Central US
    North Europe
    West Europe
    Southeast Asia
    West US 2
    Canada Central
    Central India
    

提交回复
热议问题