Referencing a Managed Service Identity in ARM-template deploy

我们两清 提交于 2019-12-03 02:36:54

I just struggled with this myself. The solution that worked for me was found deep in the comments here.

Essentially, you create a variable targeting the resource you are creating with the MSI support. Then you can use the variable to fetch the specific tenantId and principalId values. Not ideal, but it works. In my examples, I'm configuring Key Vault permissions for a Function App.

To create the variable, use the syntax below.

"variables": {
    "identity_resource_id": "[concat(resourceId('Microsoft.Web/sites', variables('appName')), '/providers/Microsoft.ManagedIdentity/Identities/default')]"
}

To get the actual values for the tenantId and principalId, reference them with the following syntax:

{
    "tenantId": "[reference(variables('identity_resource_id'), '2015-08-31-PREVIEW').tenantId]",
    "objectId": "[reference(variables('identity_resource_id'), '2015-08-31-PREVIEW').principalId]"
}

Hope this helps anyone who comes along with the same problem!

Here are a few sample templates: https://github.com/rashidqureshi/MSI-Samples that show a) how to grant RBAC access to ARM resources b) how to create access policy for keyvault using the OID of the MSI

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!