Reputation: 303
In Bicep I have a main bicep which calls
App service module looks like below, it uses output from user assigned managed id and is assigned in identity for app service:
main bicep
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 ]
}
App service template
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 for managed identity - user assigned
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
If I need an app service to be deployed without managed id I want to use the same bicep as module so I do not want this userassignedmanagedid to be a mandatory parameter. How do I make it happen?
Upvotes: 0
Views: 3492
Reputation: 29736
Optional parameters are defined using a default value.
Then you can build the identity block dynamically:
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
}
}
Upvotes: 2