我正在尝试创建一个策略来检查数组中的所有标签名称,并审核是否找不到允许的值。我想在不为每个标签名称创建参数的情况下完成此任务。
以下是检测 1 个或多个标签名称的策略:
{
"mode": "Indexed",
"policyRule": {
"if": {
"allOf": [
{
"field": "[concat('tags[', parameters('tagName1'), ']')]",
"exists": "false"
},
{
"field": "[concat('tags[', parameters('tagName2'), ']')]",
"exists": "false"
}
]
},
"then": {
"effect": "audit"
}
},
"parameters": {
"tagName1": {
"type": "String",
"metadata": {
"displayName": "Tag Name 1",
"description": "Name of first tag, such as 'environment'"
}
},
"tagName2": {
"type": "String",
"metadata": {
"displayName": "Tag Name 2",
"description": "Name of second tag, such as 'owner'"
}
}
}
}
我希望在单个数组中进行检查。就像允许的位置策略一样。所以参数会是这样的:
"parameters": {
"tagNames": {
"type": "Array",
"metadata": {
"description": "List of tag names to audit",
"displayName": "Tag Names"
},
"allowedValues": [
"environment",
"costCenter",
"owner"
]
}
},
这可能吗?
如果没有,有人可以解释为什么吗?为了我的理解。谢谢
为允许的标签名称数组创建 Azure 策略 - 而不是每个标签名称的参数。
这是使用值数组的更新策略。
{
"mode": "All",
"policyRule": {
"if": {
"not": {
"anyOf": [
{
"field": "tags",
"exists": "true"
},
{
"allOf": [
{
"field": "tags",
"exists": "false"
},
{
"not": {
"field": "tags[*]",
"in": "[parameters('tagNames')]"
}
}
]
}
]
}
},
"then": {
"effect": "audit"
}
},
"parameters": {
"tagNames": {
"type": "Array",
"metadata": {
"displayName": "Tag Names",
"description": "List of tag names to audit"
},
"allowedValues": [
"environment",
"costCenter",
"owner"
]
}
}
}
政策分配: