【发布时间】:2019-01-10 21:23:37
【问题描述】:
我已经创建了一个 Azure 策略,如果用户没有使用键“Env”或“使用”指定标签,我想拒绝创建资源组
但是当我使用 Env 标签创建资源组时它会阻止我,它只允许我同时添加 env 和 use 的标签。
根据我的理解,azure 策略中的“anyof”被用作“OR”,但我的代码表现不一样
{
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Resources/subscriptions/resourceGroups"
},
{
"anyof": [
{
"field": "tags.Env",
"exists": false
},
{
"field": "tags.use",
"exists": false
}
]
}
]
},
"then": {
"effect": "deny"
}
}
根据 Chris 的建议,我已经处理了标签名称和值,但它在政策中给了我一个错误,它没有采用“NOT”
{
"mode": "all",
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Resources/subscriptions/resourceGroups"
},
{
"not":{
{
"field": "tags.Env",
"equals" : "Prod"
},
{
"field": "tags.OS",
"equals" : "windows"
}
}
}
]
},
"then": {
"effect": "deny"
}
},
"parameters": {}
}
【问题讨论】:
标签: azure azure-resource-manager azure-resource-group