如何在Azure应用服务中指定分层应用设置?

3

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

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

在代码中,它们被使用如下- config["ApplicationInsights:InstrumentationKey"]

然而,在尝试提供ApplicationInsights:InstrumentationKey给应用服务terraform配置时:

 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": "..."
    }

我们如何在应用程序服务配置中提供它?
1个回答

3

正如错误所示,“ApplicationInsights:InstrumentationKey”名称的AppSetting是不允许的。通过将Instrumentation Key添加到Azure应用程序的App Settings中,可以将Azure Function或Azure应用程序服务与Application Insights实例关联起来。您应该使用:

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

你可以在此示例中获取更多详细信息。


请查看编辑1 - undefined
5
如果您在名称中有类似 ApplicationInsights: InstrumentationKey 的嵌套 JSON 键结构,则需要将 ApplicationInsights__InstrumentationKey 作为键名。因此请注意,任何 : 都应替换为 __(即双下划线)。app_settings 是一个键值对。 - undefined

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接