【发布时间】:2021-05-13 10:37:50
【问题描述】:
目标:将 Azure 策略部署到管理组,以便在其职权范围内的资源中缺少某些标签时,应用资源组中的指定标签
问题:将此模板部署到管理组会导致“'此位置不需要模板函数'RESOURCEGROUP'。”
有一个相当简单的结构,类似于:
<Management Group> - <Subscription 1> - <Resource Group 1> - <Resource A>
- <Resource Group 2> - <Resource B>
- <Subscription 2> - <Resource Group 3> - <Resource C>
- <Resource D>
有一个使用嵌套策略定义的相当简单的模板:
......
"resources": [
{
"type": "Microsoft.Authorization/policyDefinitions",
"apiVersion": "2019-09-01",
"name": ".",
"properties": {
"policyType": "Custom",
"mode": "Indexed",
"displayName": ".",
"description": ".",
"metadata": {
"category": "Tags"
},
"policyRule": {
"if": {
"anyOf": [
{
"field": "tags['costCenter']",
"exists": "false"
},
{
"field": "tags['CostCenter']",
"notin": "[parameters('allowedCostCenter')]"
}
]
},
"then": {
"effect": "modify",
"details": {
"roleDefinitionIds": [
"/providers/Microsoft.Authorization/roleDefinitions/4a9ae827-6dc8-4573-8ac7-8239d42aa03f"
],
"operations": [
{
"operation": "add",
"field": "tags['CostCenter']",
"value": "[resourcegroup().tags['CostCenter']]"
}
]
}
}
}
}
}
]
我知道您不能对不在资源组内的项目使用“resourcegroup()”,但指南建议在嵌套模板和“索引”资源上使用它应该可以工作。
- 我相当确定管道是正确的,因为我已经部署了多个审核策略
- 从门户中的试验来看,这应该是可能的
- 周围有大量的阅读材料,但我没有阅读(或至少理解)似乎对此有所帮助
我想要实现的目标可能吗?如果是这样,你能看出我做错了什么吗?
感谢您的帮助!
【问题讨论】:
标签: azure-resource-manager azure-policy