Add an output like this to your template:
"outputs": {
"AppInsightAppId": {
"type": "String",
"value": "[reference(resourceId('Microsoft.Insights/components', variables('appInsightsName')), '2014-04-01').AppId]"
}
}
For example:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"appInsightsNamePrefix": {
"defaultValue": "",
"type": "String"
}
},
"variables": {
"appInsightsName": "[concat(parameters('appInsightsNamePrefix'), uniqueString(resourceGroup().id))]"
},
"resources": [
{
"type": "Microsoft.Insights/components",
"apiVersion": "2014-04-01",
"name": "[variables('appInsightsName')]",
"location": "[resourceGroup().location]",
"kind": "web",
"properties": {
"ApplicationId": "[variables('appInsightsName')]"
}
}
],
"outputs": {
"AppInsightAppId": {
"type": "String",
"value": "[reference(resourceId('Microsoft.Insights/components', variables('appInsightsName')), '2014-04-01').AppId]"
}
}
}