我查看了 azurerm_app_service 和 azurerm_application_insights 的文档,但我只是没有找到将它们联系起来的方法。
然而,在门户的“应用服务”页面上,有一个指向“应用程序洞察”的链接,目前呈灰色显示:
那么,如何使用 terraform 启用它?
您需要进行大量的应用程序设置才能使其按预期正常工作。我必须添加才能使其全部正常工作的是:
目前似乎还无法使用 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"
}
}
通常,如果您需要在应用程序服务中启用应用程序洞察组件,则需要将
APPINSIGHTS_*
环境变量添加到 Web 应用程序的 app_settings
中。
例如,
app_settings {
"APPINSIGHTS_INSTRUMENTATIONKEY" = "${azurerm_application_insights.test.instrumentation_key}"
}
请参阅参数参考,即使它是关于 Azure 函数的。
参考: https://www.olivercoding.com/2018-06-24-terraform/
https://github.com/terraform-providers/terraform-provider-azurerm/issues/2457
有一个关键变量允许特定语言和操作系统版本:
{
"name": "ApplicationInsightsAgent_EXTENSION_VERSION",
"value": "~3",
"slotSetting": false }
参考链接: https://learn.microsoft.com/en-us/azure/azure-monitor/app/azure-web-apps-nodejs?tabs=windows