1
votes

{
   "mode":"All",
   "policyRule":{
      "if":{
         "allOf":[
            {
               "field":"type",
               "equals":"Microsoft.Insights/metricalerts"
            },
            {
               "field":"Microsoft.Insights/metricalerts/enabled",
               "equals":"true"
            }
         ]
      },
      "then":{
         "effect":"deployIfNotExists",
         "details":{
            "type":"microsoft.insights/actiongroups",
            "deploymentScope":"subscription",
            "existenceScope":"subscription",
            "existenceCondition":{
               "allOf":[
                  {
                     "field":"Microsoft.Insights/metricalerts/actions[*]",
                     "less":"1"
                  }
               ]
            },
            "roleDefinitionIds":[
               "/providers/microsoft.authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c"
            ],
            "deployment":{
               "location":"centralus",
               "properties":{
                  "mode":"incremental",
                  "parameters":{
                     "actionGroupName":{
                        "value":"ActionGroup1"
                     },
                     "actionGroupShortName":{
                        "value":"AG1"
                     }
                  },
                  "template":{
                     "$schema":"http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
                     "contentVersion":"1.0.0.0",
                     "parameters":{
                        "actionGroupName":{
                           "type":"string",
                           "metadata":{
                              "description":"Unique name (within the Resource Group) for the Action group."
                           }
                        },
                        "actionGroupShortName":{
                           "type":"string",
                           "metadata":{
                              "description":"Short name (maximum 12 characters) for the Action group."
                           }
                        }
                     },
                     "resources":[
                        {
                           "name":"[parameters('actionGroupName')]",
                           "type":"microsoft.insights/actionGroups",
                           "apiVersion":"2018-09-01",
                           "location":"global",
                           "properties":{
                              "groupShortName":"[parameters('actionGroupShortName')]",
                              "enabled":true,
                              "emailReceivers":[
                                 {
                                    "name":"TestMail",
                                    "emailAddress":"[email protected]"
                                 }
                              ],
                              "smsReceivers":[
                                 {
                                    "name":"TestSMS",
                                    "countryCode":"91",
                                    "phoneNumber":"99116"
                                 }
                              ],
                              "armRoleReceivers":[
                                 {
                                    "name":"TestCont",
                                    "roleId":"b24988ac-6180-42a0-ab88-20f7382dd24c"
                                 }
                              ]
                           }
                        }
                     ]
                  }
               }
            }
         }
      }
   },
   "parameters":{

   }
}

I'm creating a Policy and succeeded to create that, though while a re-mediate it using Remediation tasks in azure portal, it fails and prompts me following error

enter image description here

The Resource 'microsoft.insights/actiongroups/HmActionGroup' under resource group '' was not found. this is a format of resource in arm templates for policy. In my case i have provided location as "global"

enter image description here

Any help will be highly appreciated

1
well, show the policy definition? show full error text? - 4c74356b41
This is full text error as shown here : {"code":"DeploymentFailed","message":"At least one resource deployment operation failed. Please list deployment operations for details. Please see aka.ms/arm-debug for usage details.","details":[{"code":"NotFound","message":"{\r\n \"error\": {\r\n \"code\": \"ResourceNotFound\",\r\n \"message\": \"The Resource 'microsoft.insights/actiongroups/HmActionGroup' under resource group '<null>' was not found.\"\r\n }\r\n}"}]} - Sachin Kalia
@4c74356b41 I have added policy definition for your reference - Sachin Kalia
Facing the exact same issue, have you been able to resolve this @SachinKalia? - Vincent

1 Answers

0
votes

To deploy at the subscription level you need to use the subscription deployment schema in your template:

"$schema":"https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#"