Edit

Share via


any() function (Bicep)

Bicep supports a function named any() that suppresses type check errors. Use the Bicep any() function to cast a value to a type that's compatible with any data type. For example, use the any() function when a property requires a number but you need to provide a string, like '0.5'.

This function doesn't exist in the Azure Resource Manager template runtime. The Bicep any() function only affects compile-time type checking. It doesn't convert values at runtime and isn't emitted into the JSON for an Azure Resource Manager template.

Note

To help resolve type errors, let us know when missing or incorrect types required you to use the any() function. Add your details to the missing type validation/inaccuracies GitHub issue.

Syntax for the Bicep any() function

any(value)

Returns a value that's compatible with any Bicep data type.

Namespace: sys.

Parameters

Parameter Required Type Description
value Yes all types The value to convert to a compatible type.

Return value

The value in a form that's compatible with any data type in Bicep.

Examples

The following example shows how to use the Bicep any() function to provide numeric values as strings.

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')
            }
          }
        }
      }
    ]
  }
}

The function works on any assigned value in Bicep. The following example uses the Bicep any() function with a ternary expression as an argument.

publicIPAddress: any((pipId == '') ? null : {
  id: pipId
})

Next steps

For more complex uses of the any() function, see the following examples: