22
votes

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

4

4 Answers

55
votes

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"
    }
}
5
votes

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

2
votes

Try it (using azure cli)

az resource show -g $RESOURCE_GROUP -n $APP_INSIGHTS --resource-type "microsoft.insights/components" --query properties.InstrumentationKey
-1
votes

Just so that later I can find this answer ... I built upon @lily-user4045's answer and was able to dump all the properties this way:

$resourceDump=Get-AzureRmResource -ResourceGroupName myResourceGroupName*** -ResourceType Microsoft.Insights/components -ResourceName myResourceName***