Muokkaa

Jaa


Any function for Bicep

Bicep supports a function called any() to resolve type errors in the Bicep type system. You use this function when the format of the value you provide doesn't match what the type system expects. For example, if the property requires a number but you need to provide it as a string, like '0.5'. Use the any() function to suppress the error reported by the type system.

This function doesn't exist in the Azure Resource Manager template runtime. It's only used by Bicep and isn't emitted in the JSON for the built 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.

any

any(value)

Returns a value that is compatible with any 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 is compatible with any data type.

Examples

The following example shows how to use the 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 any() 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: