gpt4 book ai didi

Azure Policy - 与数组参数中的通配符匹配

转载 作者:行者123 更新时间:2023-12-03 03:50:55 26 4
gpt4 key购买 nike

我正在尝试使用 Azure 策略,并希望设置一个策略来强制执行资源组的特定命名约定。当使用特定的单一命名约定时,我已经让它按照我想要的方式工作,但我想尝试通过使用指定为数组的参数来改进功能,该数组可以包含多个允许的命名格式,因此例如在分配时传递一个参数表示资源组名称可以是 PROD-RG-???? 的策略或测试-RG-???例如,或 PROD-RG-*/TEST-RG-*。

现在我知道你不能在 match 命令中使用通配符,但我似乎无法在数组中使用匹配。如果我使用 match 或 like 它期望参数是字符串而不是数组。

我不确定是否可以使用 count 命令来执行此操作?

我还有什么其他方法可以做到这一点?

{
"properties": {
"displayName": "Test Resource Group Naming Convention",
"policyType": "Custom",
"mode": "All",
"metadata": {
"version": "1.0.0",

},
"parameters": {
"allowedRGNames": {
"type": "Array",
"metadata": {
"displayName": "Allowed Resource Group Naming Convention",
"description": "The allowed resource group naming convention. Use # for a number, ? for a letter or . for any character. Or specify specific characters to use."
}
}
},
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Resources/subscriptions/ResourceGroups"
},
{
"not": {
"anyOf": [
{
"field": "name",
"like": "[parameters('allowedRGNames')]"
}
]
}
}
]
},
"then": {
"effect": "deny"
}
}
},

}

最佳答案

您可以使用值计数(详细信息请参见 https://learn.microsoft.com/en-us/azure/governance/policy/concepts/definition-structure#policy-rule ):

{
"count": {
"value": [ "prefix1_*", "prefix2_*" ],
"name": "pattern",
"where": {
"field": "name",
"like": "[current('pattern')]"
}
},
"greater": 0
}

关于Azure Policy - 与数组参数中的通配符匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66761270/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com