You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Azure Bicep中获取用户分配托管标识的Client ID?

获取Azure Bicep创建的用户分配托管标识Client ID

在Azure Bicep中,用户分配托管标识的Client ID是资源的内置属性,无需额外定义特殊的输出参数,直接引用即可。

具体实现方式:

  1. 先定义用户分配托管标识资源:
resource userAssignedIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' = {
  name: 'myUserAssignedIdentity'
  location: resourceGroup().location
}
  1. 输出Client ID:
    直接通过资源的properties.clientId属性获取并输出:
output identityClientId string = userAssignedIdentity.properties.clientId

如果是在同一个Bicep文件内的其他资源需要使用这个Client ID(比如给VM关联身份、配置权限等),同样直接引用该属性即可,示例:

resource vm 'Microsoft.Compute/virtualMachines@2023-07-01' = {
  name: 'myVM'
  location: resourceGroup().location
  identity: {
    type: 'UserAssigned'
    userAssignedIdentities: {
      '${userAssignedIdentity.id}': {}
    }
  }
  properties: {
    // 示例:在VM自定义数据中传入Client ID
    customData: base64encode('IDENTITY_CLIENT_ID=${userAssignedIdentity.properties.clientId}')
  }
}

补充说明:

你可能在查阅文档时没留意到资源的内置属性部分,用户分配托管标识部署完成后,Azure会自动生成clientId、principalId等核心属性,这些属性都可以直接通过Bicep资源对象的properties字段访问,无需额外配置。

内容的提问来源于stack exchange,提问作者Enrico

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.29 18:12:37