azure - 如何在 ARM 模板中检索 Application Insight(驻留在另一个资源组中)的检测 key ?

标签 azure azure-application-insights azure-resource-manager azure-rm-template

有没有办法在 ARM 模板中检索 Application Insights(驻留在另一个资源组中)的 Instrumentation Key?

我已经使用以下代码使用 ARM 模板创建了一个 appInsights,

{
  "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "AppInsightsName": { "type": "string" },
    "Location": { "type": "string", "defaultValue": "westeurope" }
  },
  "variables": {
    //"apiVersion": "2018-02-01-preview",
    "apiVersion": "2016-08-01",
    "location": "[parameters('Location')]",
    "ApplicationInsightsName": "[parameters('AppInsightsName')]"
  },
  "resources": [
    {
      "apiVersion": "2014-04-01",
      "type": "Microsoft.Insights/components",
      "name": "[variables('ApplicationInsightsName')]",
      "location": "[variables('location')]",
      "kind": "other",
      "properties": {
        "applicationId": "[variables('ApplicationInsightsName')]"
      }
    }
  ]
}

现在我尝试将在另一个资源组中运行的 azure function 应用程序与此 appInsights 链接。

下面是我尝试过的代码,

{
  "name": "APPINSIGHTS_INSTRUMENTATIONKEY",
  "value": "[reference(resourceId(variables('AppInsightsResourceGroup'),'Microsoft.Insights/components', variables('ApplicationInsightsName'))).InstrumentationKey]"
}

但是我收到以下错误,

enter image description here

有人可以告诉我如何破解这个问题吗?

最佳答案

可以使用已从其他模板部署的资源的引用功能。您只需传入 apiVersion 参数,如 https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/template-functions-resource#reference 文档中所示。 。请注意,您还需要将引用的属性从“.InstrumentationKey”更改为“.properties.InstrumentationKey”。

"value": "[reference(resourceId(variables('AppInsightsResourceGroup'),'Microsoft.Insights/components', variables('ApplicationInsightsName')), '2015-05-01', 'Full').properties.InstrumentationKey]"

您可以部署以下模板进行验证(只需将两个变量替换为您的值):

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
  },
  "variables": {
      "AppInsightsResourceGroup": "myAIRG",
      "ApplicationInsightsName": "myAI"
  },
  "resources": [
  ],
  "outputs": {
      "appInsightsKey": {
          "type": "string",
          "value": "[reference(resourceId(variables('AppInsightsResourceGroup'),'Microsoft.Insights/components', variables('ApplicationInsightsName')), '2015-05-01', 'Full').properties.InstrumentationKey]"
      }
  }
}

关于azure - 如何在 ARM 模板中检索 Application Insight(驻留在另一个资源组中)的检测 key ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60507464/

相关文章:

sql-server - azure sql DB_ID 不起作用

azure - Windows Azure VPN 公共(public)访问

azure - 如果超时超过 10 分钟,Python Azure Functions 会发出警报

Azure 探查器 session 不会出现在应用程序洞察中

azure - 流分析作业部署为 Azure 资源管理器 (ARM) 模板

azure-resource-manager - 在 ARM 模板中将平台设置为 64 位

powershell - 管理 azure 资源管理器存储 powershell

azure - 如何使用 Logic 中的 HTTP 触发器在 Azure DevOps 中创建存储库

azure - 无法使用 Graph API 删除 Azure B2C 中的用户

azure - 如何导出Azure工作簿的ARM模板?