Bicep error code - BCP401

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

Error description

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

Examples

The following example raises the error 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 error 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 error and warning codes, see Bicep core diagnostics.