【发布时间】:2020-04-20 09:28:14
【问题描述】:
有一个 ARM 策略用于检查 Azure 中任何 VM 上是否存在特定标签:
{
"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 虚拟机?我找不到如何过滤的方法。 IE。对于 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 虚拟机符合要求(根据标签)。
1x 策略查看只有多少 Linux 虚拟机符合要求(根据标签)。
【问题讨论】:
标签: azure azure-policy