需要创建一个将添加多个标记名称和标记值的Azure策略
需要在Azure中分配策略,在该策略中仅使用指定的标记名称和值来部署资源。
{
"properties": {
"displayName": "Enforce tag and its value",
"policyType": "BuiltIn",
"description": "Enforces a required tag and its value.",
"parameters": {
"tagName": {
"type": "String",
"metadata": {
"description": "Name of the tag, such as costCenter"
}
},
"tagValue": {
"type": "String",
"metadata": {
"description": "Value of the tag, such as headquarter"
}
}
},
"policyRule": {
"if": {
"not": {
"field": "[concat('tags[', parameters('tagName'), ']')]",
"equals": "[parameters('tagValue')]"
}
},
"then": {
"effect": "deny"
}
}
},
"id": "/providers/Microsoft.Authorization/policyDefinitions/1e30110a-5ceb-460c-a204-c1c3969c6d62",
"type": "Microsoft.Authorization/policyDefinitions",
"name": "1e30110a-5ceb-460c-a204-c1c3969c6d62"
}
代码描述了如何为单个标签添加标签名称和值。 需要添加多个标签值和标签名称。
答案 0 :(得分:0)
这样的事情怎么样:
"if": {
"not": {
"allOf": [
{
"field": "[concat('tags[', parameters('tagName1'), ']')]",
"equals": "[parameters('tagValue1')]"
},
{
"field": "[concat('tags[', parameters('tagName2'), ']')]",
"equals": "[parameters('tagValue2')]"
}
]
},
"then": {
"effect": "deny"
}
},
,您还需要2个其他参数。