I am trying to use Bicep to setup an API level diagnostic for application insights. This would be the equivalent of going into the portal, selecting the API and Settings and then enabling app insights and selecting the logger etc etc.
Currently I have the following:
resource diagnostic 'Microsoft.ApiManagement/service/apis/diagnostics@2023-09-01-preview' = {
name: 'applicationinsights'
parent: myapi
properties: {
alwaysLog: 'allErrors'
loggerId: apimLogger.id
...
and then followed by a number of variations such as:
name: '${myapi.name}/applicationinsights' (with the parent tag removed)
name: 'appinsights'
Nothing I try seems to work and I get the following error all the time on the name field:
Unable to process template language expressions for resource '/subscriptions/mysubsciption/resourceGroups/myresourcegroup/providers/Microsoft.ApiManagement/service/myapim/apis/myapi/diagnostics/applicationinsights' at line '1' and column '1474'. 'The language expression property array index '1' is out of bounds.'
I have spent a long time googling. It seems the name should be one of 'applicationinsights' or 'azuremonitor' (similar to the options when you enable in the portal) and what I have tried but nothing seems to work.
Any help appreciated!
Unable to process template language expressions for resource xxxx at line '1' and column '1474'. 'The language expression property array index '1' is out of bounds.'
As I mentioned in the comments already, the issue might be due to the inappropriate structure format of either name or a parent
resource it is referring to.
In order to provide a name
field under diagnostics provider, it must be either applicationinsights
or azuremonitor
. And make sure that the Api resource symbolic name has been given correctly to the parent
field under the same resource.
name: `applicationinsights`
or
name: `azuremonitor`
Refer SO worked by me on deploying the logger and diagnostics Api service resources more clearly.
param apimService string = 'newapimjah'
param apiname string = 'apinewjah'
resource apiManagement 'Microsoft.ApiManagement/service@2020-12-01' = {
name: apimService
location: resourceGroup().location
sku: {
name: 'Developer'
capacity: 1
}
properties: {
publisherName: 'jahnavi'
publisherEmail: 'abc@gmail.com'
}
identity: {
type: 'SystemAssigned'
}
}
resource Serviceapi 'Microsoft.ApiManagement/service/apis@2021-08-01' = {
parent: apiManagement
name: apiname
properties: {
displayName: apiname
apiRevision: '1'
subscriptionRequired: true
path: apiname
protocols: [
'https'
]
}
}
resource Insights 'Microsoft.Insights/components@2020-02-02-preview' existing = {
name: 'newapsjah1'
}
resource apiMLogging 'Microsoft.ApiManagement/service/loggers@2021-08-01'={
name: 'newloger'
parent: apiManagement
properties:{
loggerType:'applicationInsights'
description:'Logging'
credentials: {
instrumentationKey: Insights.properties.InstrumentationKey
}
}
}
resource apiManagementApids 'Microsoft.ApiManagement/service/apis/diagnostics@2023-09-01-preview'={
name:'applicationinsights'
parent: Serviceapi
properties:{
loggerId:apiMLogging.id
alwaysLog:'allErrors'
verbosity:'error'
sampling: {
percentage: 100
samplingType: 'fixed'
}
}
}
Deployment succeeded: