I have individual biceps for app insight, app service plan, and, app service.
I am creating a template bicep where I will call each of these as modules to deploy one app service. And now whenever for any of my solutions I need to deploy an app service, I will just call this template with minimum parameters so it can deploy an app service with all required supporting resources like app service plan and app insight.
The situation I am stuck with now is I need one app service plan to host two app services one for web and the other for api and each of them should have their own app insight.
The individual modules are very simple, I am still giving a sample for app service plan below:
//asp.bicep
param planName string
param planLocation string = resourceGroup().Location
param planSku string
param planTier string
resource appServicePlan 'Microsoft.Web/serverfarms@2022-03-01' = { name: planName, location: planLocation, sku: {
name: planSku
tier: planTier
]}
output appPlanId string = appServicePlan.id
Below I have the app service template where all the individual biceps are being called as modules, shown below:
//astemplate.bicep
param rgLocation string = resourceGroup().location
param name string
param planSku string
param planTier string
param appSettings array = []
param netFrameworkVersion string
var appInsightModule = '${name}-AIModule'
var appServicePlanModule = '${name}-ASPModule'
var appServiceModule = '${name}-ASModule'
module aspModule ''={
name: appServicePlanModule
params: {
planName: name
planLocation: rgLocation
planSku: planSku
planTier: planTier
}
}
module aiAppModule '' = {
name: '${appInsightModule}-forApp'
params: {
name: '${name}-ai-app'
location: rgLocation
}
}
module aiApiModule '' = {
name: '${appInsightModule}-forApi'
params: {
name: '${name}-ai-api'
location: rgLocation
}
}
module asAppModule '' = {
name: '${appServiceModule}-app'
params: {
name: '${name}-app'
rgLocation: rgLocation
appInsightsKey: aiAppModule.outputs.instrumentationkey
appServicePlanId: aspModule.outputs.appPlanId
appSettings: appSettings
netFrameworkVersion: netFrameworkVersion
}
dependsOn: [aspModule, aiAppModule]
}
module asApiModule '' = {
name: '${appServiceModule}-api'
params: {
name: '${name}-api'
rgLocation: rgLocation
appInsightsKey: aiApiModule.outputs.instrumentationkey
appServicePlanId: aspModule.outputs.appPlanId
appSettings: appSettings
netFrameworkVersion: netFrameworkVersion
}
dependsOn: [aspModule, aiApiModule]
}
What I am trying to achieve is a way to have to make just one call to app insight module and one to app service module instead of two calls each? Because I want this template to satisfy all permutation and combination. If I decide to have one app insight for all app services or one for each.
For App Insight, I was thinking of passing names app insight resources in an array and use for loop at the individual bicep level(resource) but then I got stuck with assigning the appropriate app insight to its related app service.
I hope the question is clear, please let me know if more details or other individual bicep is also required?