【问题标题】:How to get Principal Id in app service using Arm template?如何使用 Arm 模板在应用服务中获取 Principal Id?
【发布时间】:2020-07-28 05:49:42
【问题描述】:

您好,我正在编写 ARM 模板来部署我的应用服务。我想在我的手臂模板中创建系统标识。在应用服务臂模板部分,我有以下代码。

"identity": {
                "principalId": "[reference(variables('identity_resource_id'), '2017-12-01', 'Full').identity.principalId]",
                "tenantId": "[parameters('tenantId')]",
                "type": "SystemAssigned"
            }

然后在变量部分我添加了

"appServiceNameFrontEnd": "[concat(variables('defaultConvention'),'03-','FrontEnd')]"
"identity_resource_id": "[concat(resourceId('Microsoft.Web/sites', variables('appServiceNameFrontEnd')), '/providers/Microsoft.ManagedIdentity/Identities/default')]"

每当我尝试运行此程序时,都会出现以下错误

##[错误]部署模板验证失败:'1'行和'10436'列的模板资源'FrontEnd'无效:模板 此位置不应出现函数“参考”。请参见 https://aka.ms/arm-template-expressions了解使用详情..

有人可以帮助我如何获得系统分配的身份吗?任何帮助将不胜感激。谢谢

【问题讨论】:

    标签: azure azure-active-directory azure-web-app-service azure-resource-manager


    【解决方案1】:

    您不能为系统分配的身份指定 ID。 有效的模板是:

    "identity": {
        "type": "SystemAssigned"
    }
    

    tenantId 将始终是链接到订阅的租户。 如果您在其他地方需要,可以使用[subscription().tenantId]。 要在别处访问系统分配身份的 objectId,您可以使用例如:

    "objectId": "[reference(resourceId('Microsoft.Web/sites', variables('appServiceNameFrontEnd')), '2016-08-01', 'Full').identity.principalId]",
    

    (请记住将应用服务指定为对资源的依赖项,以便仅在部署应用服务后才部署它)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-11-09
      • 2022-01-22
      • 1970-01-01
      • 1970-01-01
      • 2020-11-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多