azure-resource-manager - 如何使用 Bicep 引用其他订阅中的资源?

标签 azure-resource-manager azure-bicep

我使用 Bicep 创建了一个 Azure Functions,其中使用的应用服务计划是之前在另一个订阅中创建的。

我收到以下错误:

{"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')
}

是否无法在其他订阅中引用应用服务计划?

最佳答案

默认目标范围是资源组。因此,如果您不指定目标范围,则会隐式设置资源组范围。可用范围包括资源组、订阅、管理组和租户。因此,如果另一个订阅位于同一租户或管理组下,则可以将范围设置为其中一个。例如,在您的二头肌文件中注明:

targetScope = 'tenant'

在 az cli 上:

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

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

关于azure-resource-manager - 如何使用 Bicep 引用其他订阅中的资源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69946426/

相关文章:

Azure - 按主要版本从容器注册表中检索二头肌模块

azure - 有没有办法使用 Bicep 获取在 Azure SQL Server 防火墙中配置的多个不相关的 IP 地址?

azure - 使用 Arm 或 Bicep 模板配置 Azure 函数身份验证

azure - 使用 Azure Bicep 进行 Azure EventGrid 订阅的 Webhook Url 失败

azure - 使用 Bicep 将证书从 Azure Keyvault 添加到 Azure 容器环境

azure - 将 Azure ARM 部署限制为库模板

image - Azure VM 自定义操作系统镜像 ARM 模板部署

javascript - 在 Node.js 中获取资源组的访问控制列表 (IAM)

azure - 如何在运行时更新已部署的 ARM 模板的配置?

azure - 如何使用 Bicep 通过 .Net 堆栈部署 Windows Azure 应用服务?