为 Azure Function App (Terraform) 配置应用程序见解

Kam*_*aiz 3 azure azure-application-insights terraform azure-functions

使用下面的代码片段,我可以创建应用程序见解和 function_app,但我不确定如何配置 function-app 以使用创建的应用程序见解。

module "resource_group" {
  source      = "git::ssh://address"
  environment = "${var.environment}"
  application = "${var.application}"
  app_version = "${var.app_version}"
}

module "function_app" {
  source                            = "git::ssh://address"
  environment                       = "${var.environment}"
  application                       = "${var.application}"
  resource_group_name               = "${module.resource_group.name}"
  app_version                       = "${var.app_version}"
  app_service_plan_id               = "${module.app_service_plan.id}"
  storage_primary_connection_string = "${module.storage_account.primary_connection_string}"
}

resource "azurerm_application_insights" "application_insights" {
  name                = "${var.environment}-${var.application}-appInsights"
  location            = "${module.resource_group.location}"
  resource_group_name = "${module.resource_group.name}"
  application_type    = "Web"
}
Run Code Online (Sandbox Code Playgroud)

但是当我访问azure> function_app > Monitor时,它仍然显示配置application_insights。

配置应用程序洞察

有什么建议吗?

Ken*_*SFT 12

请参阅此处的示例:https ://www.olivercoding.com/2018-06-24-terraform/ 。您需要将 添加APPINSIGHTS_INSTRUMENTATIONKEYapp_settings您的函数应用程序中。

更新 - 10/09/2023

在块内添加application_insights_connection_stringand是新方法。Terraform 自动设置地图。application_insights_keysite_configapp_settings

图片来源:Rajesh Swarnkar

  • 我认为,这已经改变了,使用 0.12.6 我现在去 `app_settings =`: ` app_settings = { "APPINSIGHTS_INSTRUMENTATIONKEY" = "${azurerm_application_insights.appInsight.instrumentation_key}" }` (2认同)