【问题标题】:How to reference resources in other subscriptions with Bicep?如何使用 Bicep 引用其他订阅中的资源?
【发布时间】:2021-11-12 16:55:38
【问题描述】:

我使用 Bicep 使用之前在另一个订阅中创建的应用服务计划来创建 Azure 函数。

我收到以下错误:

{"status":"Failed","error":{"code":"DeploymentFailed","message":"At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/DeployOperations for usage details.","details":[{"code":"NotFound","message":"{\r\n  \"Code\": \"NotFound\",\r\n  \"Message\": \"Cannot find ServerFarm with name asp-intsharedep-prod.\",\r\n  \"Target\": null,\r\n  \"Details\": [\r\n    {\r\n      \"Message\": \"Cannot find ServerFarm with name myasp.\"\r\n    },\r\n    {\r\n      \"Code\": \"NotFound\"\r\n    },\r\n    {\r\n      \"ErrorEntity\": {\r\n        \"ExtendedCode\": \"51004\",\r\n        \"MessageTemplate\": \"Cannot find {0} with name {1}.\",\r\n        \"Parameters\": [\r\n          \"ServerFarm\",\r\n          \"myasp\"\r\n        ],\r\n        \"Code\": \"NotFound\",\r\n        \"Message\": \"Cannot find ServerFarm with name myasp.\"\r\n      }\r\n    }\r\n  ],\r\n  \"Innererror\": null\r\n}"}]}}

它只是一个简单的二头肌文件,没有模块,没有 targetScope。我参考我的应用服务计划:

resource serverFarm 'Microsoft.Web/serverfarms@2020-06-01'  existing = {
  name: aspName
  scope: resourceGroup('subscriptionid','rg-shared-asp')
}

在其他订阅中不能引用应用服务计划吗?

【问题讨论】:

  • 您是否已使用您用于部署二头肌文件的用户帐户/服务主体读取其他订阅的权限?
  • 您是否尝试过使用类似的方式直接引用serverFarmIdresourceId('subscriptionid', 'rg-shared-asp', 'Microsoft.Web/serverfarms', aspName)
  • 我已阅读许可,当我使用具有 resourceId 方法的引用时,我遇到了同样的错误。

标签: azure-resource-manager azure-bicep


【解决方案1】:

默认目标范围是资源组。因此,如果您不声明目标范围,则会隐式设置资源组范围。可用范围是资源组、订阅、管理组和租户。因此,如果另一个订阅在同一个租户或管理组下,您可以将范围设置为它们中的任何一个。例如,在你的二头肌文件中声明:

targetScope = 'tenant'

在 az cli 上:

az deployment tenant create \
  --name demoTenantDeployment \
  --location WestUS \
  --template-file main.bicep

https://docs.microsoft.com/en-us/azure/azure-resource-manager/bicep/scope-extension-resources#apply-at-deployment-scope

【讨论】:

  • 但是我真的需要在管理组级别进行部署吗?我想部署一个资源组,我需要在其他订阅中引用一个应用服务计划。
  • @alefa240 您的订阅是否属于同一租户或管理组?
  • 是的,是否在同一个租户中。
  • @alefa240,我已经更新了租户目标范围的内容。让我知道这是否适合您。
  • 我想在租户范围内进行部署时它会起作用。在不同订阅中访问 asp 的需要消失了,所以我没有机会测试解决方案。
猜你喜欢
  • 2022-08-14
  • 2011-03-18
  • 1970-01-01
  • 1970-01-01
  • 2020-07-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-09-07
相关资源
最近更新 更多