Azure Bicep BP165 错误 - 资源的计算范围必须与 Bicep 文件的范围匹配才能部署

问题描述 投票:0回答:2

我正在尝试使用 bicep 将 apim 后端资源部署到现有 apim 实例中。这是我的 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}}'
        ]
      }
    }
  }
}

但是,vscode 给出以下错误:

资源的计算范围必须与其 Bicep 文件的计算范围相匹配 可部署。该资源的范围是根据“范围”计算的 分配给祖先资源“apim”的属性值。你必须使用 将资源部署到不同范围的模块.bicep(BCP165)

如果我删除后端资源的部分,二头肌模块可以正常工作。

有人看到我做错了什么吗?

azure azure-resource-manager azure-api-management azure-rm-template azure-bicep
2个回答
0
投票

问题的原因是用于执行二头肌的“az部署组创建”命令传递了错误的资源组的名称。


0
投票

如果其他人面临这个问题,并且您从部署到订阅的 main.bicep 文件传递正确的资源组,则完全删除范围属性:

resource APIM 'Microsoft.ApiManagement/service@2023-03-01-preview' existing = {
  name: APIManagementName
}
© www.soinside.com 2019 - 2024. All rights reserved.