有条件地在函数应用模板中添加用户分配的托管身份

问题描述 投票:0回答:1

如果

IDENTITY_RESOURCE_ID1
参数设置为 true,是否可以更新以下模板以有条件地包含
addIdentity1

{
    "apiVersion": "2018-11-01",
    "name": "[parameters('name')]",
    "type": "Microsoft.Web/sites",
    "kind": "functionapp",
    "location": "[parameters('location')]",
    "identity": {
        "type": "SystemAssigned,UserAssigned",
        "userAssignedIdentities": {
            "IDENTITY_RESOURCE_ID1": {},
            "IDENTITY_RESOURCE_ID2": {}
        }
    },
    "tags": null,
    // ...
}
azure azure-functions azure-rm-template azure-managed-identity
1个回答
0
投票

您可以使用union功能。

这是二头肌样本(

main.bicep
):

param location string = resourceGroup().location
param name string
param addIdentity1 bool

resource webApp 'Microsoft.Web/sites@2018-11-01' = {
  name: name
  location: location
  identity: {
    type: 'SystemAssigned, UserAssigned'
    userAssignedIdentities: union(
      {
        'IDENTITY_RESOURCE_ID2': {}
      },
      addIdentity1
        ? {
            'IDENTITY_RESOURCE_ID1': {}
          }
        : {}
    )
  }
}

运行 Az Cli 命令

az bicep build --file .\main.bicep
,将为您提供此 ARM 模板:

{
  "type": "Microsoft.Web/sites",
  "apiVersion": "2018-11-01",
  "name": "[parameters('name')]",
  "location": "[parameters('location')]",
  "identity": {
    "type": "SystemAssigned, UserAssigned",
    "userAssignedIdentities": "[union(createObject('IDENTITY_RESOURCE_ID2', createObject()), if(parameters('addIdentity1'), createObject('IDENTITY_RESOURCE_ID1', createObject()), createObject()))]"
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.