How can I retrieve the instrumentation key for an Application Insights instance in an Azure Resource Group Template? How can I retrieve the instrumentation key for an Application Insights instance in an Azure Resource Group Template? azure azure

How can I retrieve the instrumentation key for an Application Insights instance in an Azure Resource Group Template?


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


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


Try it (using azure cli)

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