【问题标题】:How to specify hierarchical app settings in the Azure App Service?如何在 Azure 应用服务中指定分层应用设置?
【发布时间】:2020-02-12 08:36:27
【问题描述】:

appsettings.json 允许我们指定分层设置:

    "ApplicationInsights": {
        "InstrumentationKey": "..."
    }

在代码中它们是这样使用的 - config["ApplicationInsights:InstrumentationKey"]

但是,尝试在应用服务 terraform 配置中提供 ApplicationInsights:InstrumentationKey

 app_settings = {
    "ApplicationInsights:InstrumentationKey"   = data.azurerm_application_insights.instance.instrumentation_key
  }

导致以下错误消息:

 Error: Error updating Application Settings for App Service "app505-dfpg-qa2-web-eastus2-gateway-apsvc": web.AppsClient#UpdateApplicationSettings: Failure responding to request: StatusCode=400 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="BadRequest" Message="AppSetting with name 'ApplicationInsights:InstrumentationKey' is not allowed." Details=[{"Message":"AppSetting with name 'ApplicationInsights:InstrumentationKey' is not allowed."},{"Code":"BadRequest"},{"ErrorEntity":{"Code":"BadRequest","ExtendedCode":"04072","Message":"AppSetting with name 'ApplicationInsights:InstrumentationKey' is not allowed.","MessageTemplate":"AppSetting with name '{0}' is not allowed.","Parameters":["ApplicationInsights:InstrumentationKey"]}}]

从表面上看,这个 Azure 在抱怨,而不是 terraform。

那么,如果有的话,该怎么做呢?

编辑 1

请注意,这只是一个示例。我同样可以要求以下分层设置:

    "YabaDabaDoo": {
        "YogiBear": "..."
    }

我们如何在应用服务配置中提供它?

【问题讨论】:

    标签: azure azure-web-app-service


    【解决方案1】:

    如错误所示,不允许使用名称为“ApplicationInsights:InstrumentationKey”的 AppSetting。通过将检测密钥添加到 Azure 应用程序的应用程序设置,Azure 函数或 Azure 应用程序服务与 Application Insights 实例相关联。你应该使用

    app_settings {
        "APPINSIGHTS_INSTRUMENTATIONKEY" = "${data.azurerm_application_insights.instance.instrumentation_key}"
      }
    

    您可以在this example获取更多详细信息。

    【讨论】:

    • 请参阅EDIT 1
    • blog, if you have nested json key structure in your name like ApplicationInsights:InstrumentationKey you will need to have ApplicationInsights__InstrumentationKey as key name. So notice that any : should be replaced by __ (i.e. double underscore). 中的一些提示另外,app_settings 是一个键值对。
    猜你喜欢
    • 2022-11-29
    • 1970-01-01
    • 2019-09-06
    • 2016-08-12
    • 2021-09-05
    • 2015-12-03
    • 2020-04-04
    • 2018-05-27
    • 2017-08-28
    相关资源
    最近更新 更多