Edit

Share via


Bicep diagnostic code - BCP034

This diagnostic occurs when you have a type mismatch within an array, specifically that an item provided in an array doesn't match the data type expected by the containing property.

Description

The enclosing array expected an item of type "module[] | (resource | module) | resource[]", but the provided item was of type "string".

Level

Warning / Error

Solution

Ensure that every item you place into an array property matches the expected data type required by that property.

Examples

The dependsOn property expects an array of resource symbolic names or module symbolic names defined in the current file. It doesn't accept resource IDs, strings, or variables containing resource names.

// Define a variable holding the Storage Account name
param storageAccountName string = uniqueString(resourceGroup().id, 'stgacct')

// Define the Storage Account resource
resource stg 'Microsoft.Storage/storageAccounts@2025-06-01' = {
  name: storageAccountName
  location: resourceGroup().location
  sku: {
    name: 'Standard_LRS'
  }
  kind: 'StorageV2'
}

// Define the Web App resource that depends on the Storage Account
resource webApp 'Microsoft.Web/serverfarms@2025-03-01' = {
  name: 'my-app-service-plan'
  location: resourceGroup().location
  sku: {
    name: 'B1'
  }
  dependsOn: [
    // BCP034: Expected 'resource', but got 'string'
    // This is WRONG: it's a string, not the resource reference
    storageAccountName
  ]
}

You can fix the diagnostic by using the resource symbolic name instead of the string:

// Define a variable holding the Storage Account name
param storageAccountName string = uniqueString(resourceGroup().id, 'stgacct')

// Define the Storage Account resource
resource stg 'Microsoft.Storage/storageAccounts@2025-06-01' = {
  name: storageAccountName
  location: resourceGroup().location
  sku: {
    name: 'Standard_LRS'
  }
  kind: 'StorageV2'
}

// Define the Web App resource that depends on the Storage Account
resource webApp 'Microsoft.Web/serverfarms@2025-03-01' = {
  name: 'my-app-service-plan'
  location: resourceGroup().location
  sku: {
    name: 'B1'
  }
  dependsOn: [
    stg
  ]
}

Next steps

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