Bicep 支持一个名为 any() 禁止类型检查错误的函数。 使用 Bicep any() 函数将值强制转换为与任何数据类型兼容的类型。 例如,当属性需要数字但需要提供字符串时,请使用 any() 函数,例如 '0.5'。
Azure 资源管理器模板运行时中不存在此函数。 Bicep any() 函数仅影响编译时类型检查。 它不会在运行时转换值,也不会将其发送到 Azure 资源管理器模板的 JSON 中。
注释
为了帮助解决类型错误,请告诉我们何时缺少或不正确的类型需要使用函数 any() 。 将详细信息添加到 缺少的类型验证/不准确 的 GitHub 问题。
Bicep any() 函数的语法
any(value)
返回与任何 Bicep 数据类型兼容的值。
命名空间: sys。
参数
| 参数 | 必选 | 类型 | DESCRIPTION |
|---|---|---|---|
| 价值 | 是的 | 所有类型 | 要转换为兼容类型的值。 |
返回值
在 Bicep 中与任何数据类型兼容的格式中的值。
例子
以下示例演示如何使用 Bicep any() 函数将数值作为字符串提供。
resource wpAci 'Microsoft.ContainerInstance/containerGroups@2023-05-01' = {
name: 'wordpress-containerinstance'
location: location
properties: {
containers: [
{
name: 'wordpress'
properties: {
...
resources: {
requests: {
cpu: any('0.5')
memoryInGB: any('0.7')
}
}
}
}
]
}
}
该函数适用于 Bicep 中的任何赋值。 以下示例使用具有三元表达式的 Bicep any() 函数作为参数。
publicIPAddress: any((pipId == '') ? null : {
id: pipId
})
后续步骤
有关函数的 any() 更复杂的用法,请参阅以下示例: