Edit

Bicep diagnostic code - BCP033

This diagnostic occurs when you assign a value of a mismatched data type.

Description

Expected a value of type <data-type> but the provided value is of type <data-type>.

Level

Warning / Error

Solution

Use the expected data type. If the provided value is a token, enclose it in the any() function to mitigate the issue.

Examples

The following example raises the diagnostic because the expected data type is a string. The actual provided value is an integer:

var myValue = 5

output myString string = myValue

You can fix the diagnostic by providing a string value:

var myValue = '5'

output myString string = myValue

In Azure Bicep, encountering Error BCP033 while using deployment().location as a default value for a parameter restricted by an @allowed decorator is a common scenario. This error happens because of Bicep's strict compile-time type-safety mechanism. For example:

targetScope = 'subscription'

@allowed([
  'southcentralus'
  'eastus2euap'
])
param location string = deployment().location

If you want to keep the convenience of defaulting to the metadata location of the current deployment, you can bypass the compile-time type check by using Bicep's any() function. This function tells the compiler to treat the expression as loosely typed:

targetScope = 'subscription'

@allowed([
  'southcentralus'
  'eastus2euap'
])
// The any() function suppresses the BCP033 type-mismatch error
param location string = any(deployment().location)

If your deployment is rigidly bound to a single region, you can avoid using the dynamic deployment().location metadata altogether and explicitly assign a default value that exists inside your list.

Next steps

For more information about Bicep diagnostics, see Bicep core diagnostics.