gpt4 book ai didi

Azure 策略要求创建特定标签,但不使用默认值?

转载 作者:行者123 更新时间:2023-12-02 23:44:18 25 4
gpt4 key购买 nike

有没有一种方法可以创建一个 Azure 策略,要求在创建资源时在资源上存在标签,但不检查特定值?我见过的所有例子都是“检查标签 X 是否存在,并且具有值 Y”。

我只想让用户知道“您需要在此资源上放置标记 X”,因为该值是用户定义的,因此我无法强制执行特定值。

例如 - 我需要对每个资源使用“BillingCode”,但只有创建资源的人知道其正确的计费代码,因为每个人或项目的计费代码都不同。

最佳答案

您可以使用订阅策略来实现此目的。除非满足某些规则,否则它们将阻止部署 Azure 资源。

以下示例取自 here 。您可以使用 notMatch 运算符而不是下面的直接匹配来修改此示例。 More operators here .

{
"properties": {
"displayName": "Enforce tag and its value on resource groups",
"description": "Enforces a required tag and its value on resource groups.",
"mode": "All",
"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": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Resources/subscriptions/resourceGroups"
},
{
"not": {
"field": "[concat('tags[',parameters('tagName'), ']')]",
"equals": "[parameters('tagValue')]"
}
}
]
},
"then": {
"effect": "deny"
}
}
}
}

关于Azure 策略要求创建特定标签,但不使用默认值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54972628/

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