azure - Azure 上 'Work pace based Application Insight' 的 Terraform 部署

标签 azure terraform azure-functions azure-application-insights terraform-provider-azure

我一直在尝试找出一种方法来为我的应用程序服务/az 函数准备 terraform 模板,在其中我可以将其连接到应用程序 Insight,同时通过 Terraform 创建它们。嗯,它有效,但是应用程序 Insight 显示

Migrate this resource to Workspace-based Application Insights to gain support for all of the capabilities of Log Analytics, including Customer-Managed Keys and Commitment Tiers. Click here to learn more and migrate in a few clicks.

我如何从 terraform 获得它?从 terraform 的文档页面来看,没有提及此类设置。感谢您对此提供的帮助。 这是 az-function 的 terraform 代码

    resource "azurerm_linux_function_app" "t_funcapp" {
  name                = "t-function-app"
  location            = local.resource_location
  resource_group_name = local.resource_group_name
  service_plan_id     = azurerm_service_plan.t_app_service_plan.id

  storage_account_name       = azurerm_storage_account.t_funcstorage.name
  storage_account_access_key = azurerm_storage_account.t_funcstorage.primary_access_key

  site_config {
    application_stack {
      java_version = "11"
    }
    remote_debugging_enabled = false
    ftps_state = "AllAllowed"
  }
  app_settings = {
    APPINSIGHTS_INSTRUMENTATIONKEY = "${azurerm_application_insights.t_appinsights.instrumentation_key}"
  }
  depends_on = [
    azurerm_resource_group.t_rg,
    azurerm_service_plan.t_app_service_plan,
    azurerm_storage_account.t_funcstorage,
    azurerm_application_insights.t_appinsights
  ]
}

这是应用洞察的 terraform 代码

resource "azurerm_application_insights" "t_appinsights" {
  name                = "t-appinsights"
  location            = local.resource_location
  resource_group_name = local.resource_group_name
  application_type    = "web"
  depends_on = [
    azurerm_log_analytics_workspace.t_workspace
  ]
}

output "instrumentation_key" {
  value = azurerm_application_insights.t_appinsights.instrumentation_key
}

output "app_id" {
  value = azurerm_application_insights.t_appinsights.app_id
}

最佳答案

您必须创建 Log Analytics 工作区并将其添加到您的 Application Insights。

例如

resource "azurerm_log_analytics_workspace" "example" {
  name                = "workspace-test"
  location            = local.resource_location
  resource_group_name = local.resource_group_name
  sku                 = "PerGB2018"
  retention_in_days   = 30
}

resource "azurerm_application_insights" "t_appinsights" {
  name                = "t-appinsights"
  location            = local.resource_location
  resource_group_name = local.resource_group_name
  workspace_id        = azurerm_log_analytics_workspace.example.id
  application_type    = "web"
}

output "instrumentation_key" {
  value = azurerm_application_insights.t_appinsights.instrumentation_key
}

output "app_id" {
  value = azurerm_application_insights.t_appinsights.app_id
}

希望这有帮助!

关于azure - Azure 上 'Work pace based Application Insight' 的 Terraform 部署,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73814100/

相关文章:

azure - Microsoft Azure Active Directory 权限检查实现/RBAC

azure - pipelinemapred waitoutputthreads 子进程失败,代码为 255

terraform - 为节点池指定 "dotted"k8s 标签?

google-cloud-platform - 如何将 GCP 服务帐户 key.json 内容传递到 Terraform Cloud 而不在 VCS 中提交?

terraform - Terraform可以用于配置本地服务器吗?

c# - 等待持久实体值发生变化

c# - 我可以为 Azure Functions 绑定(bind)表达式配置默认值吗?

azure 应用程序设置-如何添加嵌套项目

azure - 发布 URL https ://waws-prod-am2-xxx.publish.azurewebsites.windows.net/无法访问

c# - 多个异步 Cosmos DB 查询导致 "InvalidCastExceptions"