【发布时间】:2023-02-06 19:27:39
【问题描述】:
我正在尝试创建一个审核 vms 的 azure 策略。我要满足的条件是 vm 具有参数指定的所有标签,并且所有这些对应的标签都包含一个值。我在下面使用的第一个条件。然而,要确定它们是否为空白有点更具挑战性,因为看起来您不能在字段键中使用 current() 。
{
"parameters": {
"requiredTags": {
"type": "Array",
"metadata": {
"displayName": "Required Tags",
"description": "The list of tags that should exist on the virtual machine"
}
}
},
"policyRule": {
"if": {
"allof": [
{
"field": "type",
"equals": "Microsoft.Compute/VirtualMachines"
},
{
"count": {
"value": "[parameters('requiredTags')]",
"where": {
"field": "tags",
"containsKey": "[current()]"
}
},
"notEquals": "[length(parameters('requiredTags'))]"
},
{
"count": {
"value": "[parameters('requiredTags')]",
"where": {
"field": "[concat('tags[', current(), ']')]",
"notEquals": ""
}
},
"notEquals": "[length(parameters('requiredTags'))]"
}
]
},
"then": {
"effect": "audit"
}
}
}
【问题讨论】:
-
是的。我知道我可以通过 cli、powershell 和 graph api 来做,但如果我可以添加为策略,那么它会得到一致的审计。
标签: json azure tags azure-policy