用于添加多个标记名称和标记值的 Azure Policy
Azure Policy to add multiple tag names and tag values
需要创建一个 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"
}
代码描述了如何为单个标签添加标签名称和值。
需要添加多个标签值和标签名称。
这样的事情怎么样:
"if": {
"not": {
"allOf": [
{
"field": "[concat('tags[', parameters('tagName1'), ']')]",
"equals": "[parameters('tagValue1')]"
},
{
"field": "[concat('tags[', parameters('tagName2'), ']')]",
"equals": "[parameters('tagValue2')]"
}
]
},
"then": {
"effect": "deny"
}
},
你还需要 2 个额外的参数。
需要创建一个 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"
}
代码描述了如何为单个标签添加标签名称和值。 需要添加多个标签值和标签名称。
这样的事情怎么样:
"if": {
"not": {
"allOf": [
{
"field": "[concat('tags[', parameters('tagName1'), ']')]",
"equals": "[parameters('tagValue1')]"
},
{
"field": "[concat('tags[', parameters('tagName2'), ']')]",
"equals": "[parameters('tagValue2')]"
}
]
},
"then": {
"effect": "deny"
}
},
你还需要 2 个额外的参数。