有一个用于检查Azure中任何VM上特定标记是否存在的ARM策略:
{
"mode": "Indexed",
"policyRule": {
"if": {
"AllOf": [
{
"field": "type",
"in": [
"microsoft.compute/virtualmachines",
"Microsoft.ClassicCompute/virtualMachines"
]
},
{
"field": "[concat('tags[', parameters('tagName'), ']')]",
"exists": "false"
}
]
},
"then": {
"effect": "audit"
}
},
"parameters": {
"tagName": {
"type": "String",
"metadata": {
"displayName": "tagName",
"description": "Tag used to unequally identify a VM"
}
}
}
}
问题:
如何创建单独的策略,一个针对Linux,另一个针对Windows VM?我找不到如何过滤的方法。即对于Windows,我使用以下策略脚本:
{
"mode": "Indexed",
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Compute/virtualMachines"
},
{
"field": "Microsoft.Compute/imagePublisher",
"in": [
"MicrosoftWindowsServer",
"MicrosoftSQLServer"
]
},
{
"field": "[concat('tags[', parameters('tagName'), ']')]",
"exists": "false"
}
]
},
"then": {
"effect": "audit"
}
},
"parameters": {
"tagName": {
"type": "String",
"metadata": {
"displayName": "tagName",
"description": "Tag used to help unequally identify a VM"
}
}
}
}
但是上面显示了Windows和Linux,因为它的逻辑是“如果VM是Windows且具有特定标签,则表示符合标准;否则,如果没有特定标签或VM是Linux,则视为不符合标准”。
需要:
1x策略,以查看仅兼容Windows VM的数量(根据标签)。
1x策略,以查看仅兼容Linux VM的数量(根据标签)。
答案 0 :(得分:0)
尝试使用Microsoft.Compute / virtualMachines / imagePublisher而不是Microsoft.Compute / imagePublisher
答案 1 :(得分:0)
{
"mode": "Indexed",
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Compute/virtualMachines"
},
{
"field": "Microsoft.Compute/imagePublisher",
"in": [
"MicrosoftWindowsServer",
"MicrosoftSQLServer"
]
}
]
},
"then": {
"effect": "auditIfNotExists",
"details": {
"type": "Microsoft.Compute/virtualMachines",
"name": "[field('name')]",
"existenceCondition": {
"field": "[concat('tags[', parameters('tagName'), ']')]",
"exists": "true"
}
}
}
},
"parameters": {
"tagName": {
"type": "String",
"metadata": {
"displayName": "tagName",
"description": "Tag used to help unequally identify a VM"
}
}
}
最终想到这个为我工作