使用ARM模板部署时如何获取Application Insights应用程序ID?

cpo*_*ign 5 azure azure-application-insights azure-rm-template

我有一个将 Application Insights 部署到 Azure 的 ARM 模板。

从那里我需要获取“应用程序 ID”

“正在监视您在发布流中部署的服务的 Application Insights 资源的应用程序 ID。在 API 访问边栏选项卡中找到它”

在此输入图像描述

Pet*_*ons 6

将如下输出添加到您的模板中:

    "outputs": {
        "AppInsightAppId": {
            "type": "String",
            "value": "[reference(resourceId('Microsoft.Insights/components', variables('appInsightsName')), '2014-04-01').AppId]"
        }
    }
Run Code Online (Sandbox Code Playgroud)

例如:

{
    "$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]"
        }
    }
}
Run Code Online (Sandbox Code Playgroud)