Search code examples
azureazure-resource-managerazure-api-managementazure-rm-templateazure-bicep

Azure Bicep BP165 Error - A resource's computed scope must match that of the Bicep file for it to be deployable


I'm trying to use bicep to deploy an apim backend resource into an existing apim instance. This is the relevant section of my apim mdoule:

resource apim 'Microsoft.ApiManagement/service@2021-08-01' existing = {
  name: apimName
  scope: resourceGroup(apimRG)
}

var funcAppName = 'func-nurseryfees-${env}-001'
resource backend 'Microsoft.ApiManagement/service/backends@2022-04-01-preview' = {
  name: 'backend_${funcAppName}'
  parent: apim
  properties: {
    description: 'backend for ${funcAppName}'
    url: 'https://func-nurseryfees-${env}-001.azurewebsites.net/api'
    protocol: 'http'
    credentials: {
      header: {
        'x-functions-key': [
          '{{func-nurseryfees-dev-001-key}}'
        ]
      }
    }
  }
}

However, vscode gives the following error:

A resource's computed scope must match that of the Bicep file for it to be deployable. This resource's scope is computed from the "scope" property value assigned to ancestor resource "apim". You must use modules to deploy resources to a different scope.bicep(BCP165)

The bicep module works ok if I remove the section for the backend resource.

Anyone see what I'm doing wrong please?


Solution

  • Cause of the problem was the 'az deployment group create' command that was used to execute the bicep was passing the name of the wrong resource group.