首页 > 解决方案 > 你如何在 Azure 中强制执行整数个标记值

问题描述

我的 Azure 政策拒绝评估以下错误的表达式。我认为问题在于,当您在门户中提供标记值时,即使打算传递整数值,它们也会作为字符串传递给 ARM。试图弄清楚如何为标签强制执行整数值作为结果

{
 "field": "tags['Longevity']",
 "less": 1
}

错误

"The policy assignment 'd9c1d0b06de841559a1cbafe' associated with the policy definition 'dee67dc2-7393-4c02-916f-92511146c970' could not be evaluated. 
A 'less' or 'lessOrEquals' or 'greater' or 'greaterOrEquals' expression expects operands of same type for comparison. The supported types are string, integer, float, ISO 8601 datetime. Please either fix the 
policy or remove the policy assignment to unblock. See https://aka.ms/policy-conditions for usage details."

在此处输入图像描述

标签: azure-policy

解决方案


Microsoft 支持提供了一个答案 答案如下,可以按预期工作。必须使用 concat() 函数看起来像是逃避抱怨方括号内的方括号

{
 "value": "[int(field(concat('tags[', 'Longevity', ']')))]",
 "less": 0
},

推荐阅读