如何在 Azure Policy 中添加动态标签?
How to add dynamic tag in Azure Policy?
我需要添加资源类型作为标签值。有人可以帮我创建这个吗?
到目前为止,我已经应用了这个示例策略。我需要添加标签名称 resource_class 和资源类型,它应该从类型中获取它,我可以将名称拆分为值中的类型名称。
{
"mode": "Indexed",
"policyRule": {
"if": {
"anyOf": [
{
"field": "tags[division]",
"exists": "false"
},
{
"field": "tags[division_code]",
"exists": "false"
}
]
},
"then": {
"effect": "append",
"details": [
{
"field": "tags[division]",
"value": "[tolower(parameters('division'))]"
},
{
"field": "tags[division_code]",
"value": "[tolower(parameters('division_code'))]"
}
]
}
},
"parameters": {
"division": {
"type": "String",
"metadata": {
"displayName": "division",
"description": "Value of the tag, such as 'production'"
}
},
"division_code": {
"type": "String",
"metadata": {
"displayName": "division_code",
"description": "Value of the tag, such as '1234'"
}
}
}
}
根据目前的文档,并非所有资源类型都支持标签。要确定您是否可以将标记应用于资源类型,请参阅 Tag support for Azure resources。
您可以使用Azure Policy Framework and there is built-in定义来达到您的要求。
基于doc.。
更多信息请参考以下链接:
我的理解是您正在尝试将资源类型添加为标记值。如果正确你可以像下面这样写
{
"field": "tags[division]",
"value": "[field('type')]"
}
我需要添加资源类型作为标签值。有人可以帮我创建这个吗?
到目前为止,我已经应用了这个示例策略。我需要添加标签名称 resource_class 和资源类型,它应该从类型中获取它,我可以将名称拆分为值中的类型名称。
{
"mode": "Indexed",
"policyRule": {
"if": {
"anyOf": [
{
"field": "tags[division]",
"exists": "false"
},
{
"field": "tags[division_code]",
"exists": "false"
}
]
},
"then": {
"effect": "append",
"details": [
{
"field": "tags[division]",
"value": "[tolower(parameters('division'))]"
},
{
"field": "tags[division_code]",
"value": "[tolower(parameters('division_code'))]"
}
]
}
},
"parameters": {
"division": {
"type": "String",
"metadata": {
"displayName": "division",
"description": "Value of the tag, such as 'production'"
}
},
"division_code": {
"type": "String",
"metadata": {
"displayName": "division_code",
"description": "Value of the tag, such as '1234'"
}
}
}
}
根据目前的文档,并非所有资源类型都支持标签。要确定您是否可以将标记应用于资源类型,请参阅 Tag support for Azure resources。
您可以使用Azure Policy Framework and there is built-in定义来达到您的要求。
基于doc.。
更多信息请参考以下链接:
我的理解是您正在尝试将资源类型添加为标记值。如果正确你可以像下面这样写
{
"field": "tags[division]",
"value": "[field('type')]"
}