Edit

Share via


Bicep diagnostic code - BCP401

This diagnostic occurs when you use expressions to define resource bodies as the Spread operator gets converted to a function. It's a limitation in JSON.

Description

The spread operator "..." is not permitted in this ___location.

Level

Error

Examples

The following example raises the diagnostic because the spread operator is used to define the resource body:

param ___location string = resourceGroup().___location
param addressPrefix string = '10.0.0.0/24'
 
resource vnet 'Microsoft.Network/virtualNetworks@2024-01-01' = {
  name: 'vnetName'
  ___location: ___location
 
  ...(addressPrefix != '' ? {
    properties: {
      addressSpace: {
        addressPrefixes: [
          addressPrefix
        ]
      }
    }
  } : {})
}

You can fix the diagnostic by using the operator in the lower level:

param ___location string = resourceGroup().___location
param addressPrefix string = '10.0.0.0/24'
 
resource vnet 'Microsoft.Network/virtualNetworks@2024-01-01' = {
  name: 'vnetName'
  ___location: ___location
 
  properties: {
    addressSpace: {
      ...(addressPrefix != '' ? {
        addressPrefixes: [
          addressPrefix
        ]        
      } : {})
    }
  }
}

Next steps

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