如何使用 terraform 将 Azure 应用程序服务与应用程序洞察资源(新的或现有的)相关联?

mar*_*ark 5 azure azure-application-insights terraform azure-web-app-service

我查看了azurerm_app_serviceazurerm_application_insights的文档,但我没有找到将它们联系起来的方法。

然而,在门户的应用服务页面上有一个指向 Application Insights 的链接,目前是灰色的: 在此处输入图片说明

那么,如何使用 terraform 启用它?

小智 10

您需要进行大量的应用程序设置才能使其按预期正常工作。为了使其全部正常工作,我必须添加以下内容:

  • “APPINSIGHTS_INSTRUMENTATIONKEY”
  • “APPINSIGHTS_PROFILERFEATURE_VERSION”
  • “APPINSIGHTS_SNAPSHOTFEATURE_VERSION”
  • “APPLICATIONINSIGHTS_CONNECTION_STRING”
  • “ApplicationInsightsAgent_EXTENSION_VERSION”
  • “诊断服务_EXTENSION_VERSION”
  • “InstrumentationEngine_EXTENSION_VERSION”
  • “SnapshotDebugger_EXTENSION_VERSION”
  • “XDT_MicrosoftApplicationInsights_BaseExtensions”
  • “XDT_MicrosoftApplicationInsights_模式”


Nan*_*ong 6

目前看来,使用 Terraform 启用应用程序洞察还无法正常工作。有一个功能请求:将 azurerm_application_insights 附加到 Github 中的 azurerm_app_service

可能可以在资源tag上设置一个azurerm_application_insights

resource "azurerm_application_insights" "test" {
  tags {
    "hidden-link:/subscriptions/<subscription id>/resourceGroups/<rg name>/providers/Microsoft.Web/sites/<site name>": "Resource"
  }
}
Run Code Online (Sandbox Code Playgroud)

通常,如果您需要在应用程序服务中启用应用程序洞察组件,则需要将APPINSIGHTS_*环境变量添加到app_settingsWeb 应用程序的环境变量中。

例如,

 app_settings {
    "APPINSIGHTS_INSTRUMENTATIONKEY" = "${azurerm_application_insights.test.instrumentation_key}"
  }
Run Code Online (Sandbox Code Playgroud)

请参阅参数参考,即使它是关于 Azure 函数的。

在此输入图像描述 参考: https://www.olivercoding.com/2018-06-24-terraform/

https://github.com/terraform-providers/terraform-provider-azurerm/issues/2457