gpt4 book ai didi

azure - Bicep 中的可选参数

转载 作者:行者123 更新时间:2023-12-03 06:20:25 26 4
gpt4 key购买 nike

在二头肌中,我有一个主要的二头肌,它会调用

  1. 部署应用服务的模块
  2. 部署托管身份的模块

应用程序服务模块如下所示,它使用用户分配的托管 ID 的输出,并在应用程序服务的身份中分配:

主要二头肌

module userAssignedManagedIdModule 'uam.bicep' = {
name: uamanagedid
params: {
location: rgLocation
name: name
}
}

module asModule 'appservicetemplate.bicep' = {
name: 'name'
params: {
appServiceName: asName
userassignedmanagedid: userAssignedManagedIdModule.outputs.managedIdentityId
}
dependsOn: [ userAssignedMID ]
}

应用服务模板

param UserAssignedIdentity string

resource appService 'Microsoft.Web/sites@2021-02-01' = {
name: appServiceName
location: rgLocation
identity: {
type: 'UserAssigned'
userAssignedIdentities: {
'${UserAssignedIdentity}':{}
}
}
properties:{
serverFarmId: appServicePlanId
siteConfig:{
alwaysOn: true
ftpsState: 'Disabled'
}
httpsOnly: true
}
}

Bicep 用于托管身份 - 用户分配

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

resource UserAssignedIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' = {
name: name
location: location
}

output managedIdentityId string = UserAssignedIdentity.id

如果我需要在没有托管 ID 的情况下部署应用程序服务,我想使用相同的二头肌作为模块,因此我不希望此 userassignedmanagementid 成为强制参数。我该如何实现它?

最佳答案

可选参数使用默认值定义。

然后您可以动态构建身份 block :

param UserAssignedIdentity string = ''

resource appService 'Microsoft.Web/sites@2021-02-01' = {
name: appServiceName
location: rgLocation
identity: empty(UserAssignedIdentity) ? {} : {
type: 'UserAssigned'
userAssignedIdentities: {
'${UserAssignedIdentity}': {}
}
}
properties: {
serverFarmId: appServicePlanId
siteConfig: {
alwaysOn: true
ftpsState: 'Disabled'
}
httpsOnly: true
}
}

关于azure - Bicep 中的可选参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75941134/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com