【发布时间】:2020-04-27 14:05:39
【问题描述】:
我正在尝试构建一个 Azure 策略,它将审核我们的 Azure 租户中的 ApplicationInsights 资源,该资源的 SamplingPercentage 值大于参数化值。目前,参数设置为“Float”类型(因为您可以指定33.3、12.5、8.3):
{
"mode": "All",
"policyRule": {
"if": {
"allOf": [{
"value": "type",
"equals": "Microsoft.Insights/components"
},
{
"value": "SamplingPercentage",
"greater": "[parameters('Maximum')]"
}]
},
"then": {
"effect": "audit"
}
},
"parameters": {
"Maximum": {
"type": "Float",
"metadata": {
"displayName": "Maximum",
"description": "Sets the maximum allowed sampling percentage."
}
}
}
}
通过 Azure 门户设置 SamplingPercentage 时,您会看到一个有效选项列表。我想将这些包含在 Maximum 参数的 AllowedValues 属性中。
第一个想法是使用 strongType(我假设它会提示 Azure 门户根据类型注入允许的值)...我一直无法找到这样的值。第二次尝试失败,因为它似乎无法创建整数的Array。当我将Maximum 参数的Type 更改为String 并声明参数时,第三次尝试失败:
"parameters": {
"Maximum": {
"type": "Array",
"metadata": {
"displayName": "Maximum",
"description": "Sets the maximum allowed sampling percentage."
},
"allowedValues": [ "100", "50", "33.3", "25", "12.5", "8.3", "4", "2", "1" ]
}
}
以及相关的条件
{
"value": "SamplingPercentage",
"greater": "[float(parameters('Maximum'))]"
}
导致此错误的原因:
使用无效参数调用了内部异常“模板语言函数“float”。该值无法转换为目标类型。'
我做错了什么?
【问题讨论】:
标签: azure azure-policy