Edit

Share via


Bicep diagnostic code - BCP420

In Bicep, every resource or module must have a known deployment scope at compile time. The scope must be statically determinable. If the scope depends on a parameter, a variable, or an expression that can't be evaluated during compilation, Bicep throws BCP420.

Description

The scope couldn't be resolved at compile time because the supplied expression is ambiguous or too complex. Scoping expressions must be reducible to a specific kind of scope without knowledge of parameter values.

Level

Error

Examples

The following code triggers BCP420 because the scope property uses a conditional expression that depends on the runtime value of the targetResourceGroupName parameter. Bicep requires that scope expressions resolve to a specific scope at compile time, without relying on parameter values or dynamic logic. Since the compiler can't determine the scope without evaluating targetResourceGroupName, it throws BCP420.

param targetResourceGroupName string = 'my-target-rg'
param storageAccountName string = 'mystorageacct'
param location string = 'eastus'

module storageModule './module.bicep' = {
  name: 'deployStorage'
  scope: empty(targetResourceGroupName) ? resourceGroup() : resourceGroup(targetResourceGroupName)
  params: {
    storageAccountName: storageAccountName
    location: location
  }
}

Next steps

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