Muokkaa

Jaa


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.