Bicep supports a special function called any() to resolve type errors in the Bicep type system. For a number of reasons, the type system may throw a false-positive error or warning. These are cases where Bicep is telling you something is wrong, even though it is correct. These cases typically manifest in one of two ways:
- There is a genuine bug in the Bicep type system
- The resource type that is being declared has an incorrect api definition (swagger spec). For example, their API definition may expect a value to be an int, even though the actual running API is expecting a string.
When either of the above occurs you can use the any() function to suppress the error.
To help us out, it would also be great if you can file a relevant issue on which false-positive you encountered. For missing or incorrect type info, you can add your details to the pinned issue we have tracking it (missing type validation/inaccuracies).
Note: This function does not actually exist in the ARM Template runtime, it is only used by the Bicep language and not emitted in the built template JSON.
In the following example, at the time of this writing, the API definition for Azure Container Instances is incorrect because the properties.containers[*].properties.resources.requests.cpu and properties.containers[*].properties.resources.requests.memoryInGB properties expect an int, but actually require a number, since the expected values can be non-integer values (i.e. 0.5). Since number types are not valid in Bicep (or ARM templates) we are forced to pass the number as a string. As a result, if I use the below code in my Bicep file, I will get warnings on those properties.
You can see this example live in the Bicep playground
resource wpAci 'microsoft.containerInstance/containerGroups@2019-12-01' = {
name: 'wordpress-containerinstance'
location: location
properties: {
containers: [
{
name: 'wordpress'
properties: {
...
resources: {
requests: {
cpu: '0.5'
memoryInGB: '0.7'
}
}
}
}
]
}
}In order to get rid of these warnings, simply wrap the relevant property value(s) in the any() function like so:
resource wpAci 'microsoft.containerInstance/containerGroups@2019-12-01' = {
name: 'wordpress-containerinstance'
location: location
properties: {
containers: [
{
name: 'wordpress'
properties: {
...
resources: {
requests: {
cpu: any('0.5')
memoryInGB: any('0.7')
}
}
}
}
]
}
}You can see in the live code in the playground, the warnings go away.
any() works on any assigned value in Bicep. You can see a more complex use of any() in the nested-vms-in-virtual-network example on line 31 of nic.bicep in which the use of any() wraps the entire ternary expression as an argument.
For more complex uses of the any() function, you can look at some of the below examples: