Search code examples
azureazure-application-insightsazure-rm-template

How to get Application Insights Application ID when deploying using ARM template?


I have an ARM template deploying Application Insights to Azure.

From there I need to get "Application Id"

"Application Id of the Application Insights resource that is monitoring the service that you are deploying in the release flow. Find it in the API access blade"

enter image description here


Solution

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