合并Action Group与Budget Alert ARM模板无资源组选择选项问题
问题根因
你遇到的问题是两个资源属于不同的Azure部署作用域:
- Action Group(microsoft.insights/actionGroups)是资源组级资源,必须部署到指定资源组下
- Budget Alert(Microsoft.Consumption/budgets)是订阅级资源,直接部署在订阅层级
你把两个不同作用域的资源直接放在模板顶层resources数组中,会导致部署上下文冲突:如果使用资源组级部署,订阅级的Budget无法创建;如果使用订阅级部署,不会出现资源组选择框,Action Group无法分配资源组导致部署失败。
正确解决方案
使用订阅级部署模板+嵌套资源组部署的结构实现需求:
- 主模板采用订阅级部署schema,部署时在订阅上下文运行,支持选择/填写Action Group所需的资源组参数
- Action Group通过嵌套部署指定目标资源组完成创建
- Budget资源直接在订阅上下文创建,通过依赖关系保证Action Group创建完成后再部署
修正后的完整模板示例
{ "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "actionGroupRGName": { "type": "string", "metadata": { "description": "Action Group部署所属的资源组名称" } }, "budgetName": { "type": "string" }, "startDate": { "type": "string" }, "endDate": { "type": "string" }, "timeGrain": { "type": "string", "allowedValues": [ "Monthly", "Quarterly", "Annually" ] }, "amount": { "type": "int" }, "firstThreshold": { "type": "int" }, "contactEmails": { "type": "array" } }, "resources": [ // 嵌套部署:创建资源组级的Action Group { "type": "Microsoft.Resources/deployments", "apiVersion": "2021-04-01", "name": "deployActionGroup", "resourceGroup": "[parameters('actionGroupRGName')]", // 指定Action Group的部署资源组 "properties": { "mode": "Incremental", "template": { "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "resources": [ { "type": "microsoft.insights/actionGroups", "apiVersion": "2019-06-01", "name": "OG", "location": "Global", "properties": { "groupShortName": "OG", "enabled": true, "emailReceivers": [ { "name": "[concat('Test','OG')]", "emailAddress": "someemailID@xxx.com", "useCommonAlertSchema": true } ] } } ], "outputs": { "actionGroupId": { "type": "string", "value": "[resourceId('microsoft.insights/actionGroups', 'OG')]" } } } } }, // 订阅级资源:Budget告警 { "type": "Microsoft.Consumption/budgets", "apiVersion": "2019-10-01", "name": "[parameters('budgetName')]", "dependsOn": [ "[subscriptionResourceId('Microsoft.Resources/deployments', 'deployActionGroup')]" ], "properties": { "timePeriod": { "startDate": "[parameters('startDate')]", "endDate": "[parameters('endDate')]" }, "timeGrain": "[parameters('timeGrain')]", "amount": "[parameters('amount')]", "category": "Cost", "notifications": { "NotificationForExceededBudget1": { "enabled": true, "operator": "GreaterThan", "threshold": "[parameters('firstThreshold')]", "contactEmails": "[parameters('contactEmails')]", "contactGroups": [ "[reference('deployActionGroup').outputs.actionGroupId.value]" ] } } } } ] }
部署说明
- 该模板为订阅级部署模板,部署时选择目标订阅后,会出现
actionGroupRGName参数输入框,填写你要部署Action Group的资源组名称即可(资源组需提前在对应订阅下创建) - 模板内置依赖关系,会先完成Action Group的创建,再创建Budget告警并自动关联Action Group的ID
内容的提问来源于stack exchange,提问作者Divyansh Saxena
相关产品推荐
相关产品推荐

