Reputation: 10322
Is there any way to retrieve the Instrumentation Key for an Application Insights instance in an Azure Resource Group template ?
I've tried the instructions here to retrieve the list of list* operations available on Azure resources, but Microsoft.Insights/components
doesn't appear in the list anywhere. It's making me think that retrieving an Instrumentation Key in the template isn't currently possible
Upvotes: 28
Views: 20204
Reputation: 336
The answer from Alex Marshall will work fine, but I just wanted to contribute by saying you could do this with Bicep as well. The syntax would be as follows:
resource appInsights 'Microsoft.Insights/components@2020-02-02' existing = {
name: 'appinsights-name'
scope: resourceGroup('rg-appinsights-resides-in')
}
output appString string = appInsights.properties.ConnectionString
output appinsight string = appInsights.properties.InstrumentationKey
Upvotes: 5
Reputation: 1563
Try it (using azure cli)
az resource show -g $RESOURCE_GROUP -n $APP_INSIGHTS --resource-type "microsoft.insights/components" --query properties.InstrumentationKey
Upvotes: 9
Reputation: 10322
After some digging and experimenting, this is what I found works:
"outputs": {
"MyAppInsightsInstrumentationKey": {
"value": "[reference(resourceId('Microsoft.Insights/components', variables('myAppInsightsInstanceName')), '2014-04-01').InstrumentationKey]",
"type": "string"
}
}
Upvotes: 61
Reputation: 793
Instrumentation Key belongs to resource, you can find it in Azure Resource manager template. If you want to find Instrumentation Key, you need to define ResourceType to Microsoft.Insights/components. Try the below code:
$resourcevalue=Get-AzureRmResource -ResourceGroupName Default-ApplicationInsights-*** -ResourceType Microsoft.Insights/components -ResourceName **hdinsights -ApiVersion 2015-05-01
$resourcevalue.Properties.InstrumentationKey
Upvotes: 5