如何在 Pulumi 上使用 "GetComponnectOutput" 访问 Azure App Insights 输出

How to access to an Azure App Insights output with "GetComponnectOutput" on Pulumi

我使用 Pulumi 创建了一个 Azure App Insights,并且 GetComponnectOutput 我收到了如下输出:

示例代码:

app_insights_key = insights.get_component_output(
    resource_group_name=temp_resources_group.name,
    resource_name=temp_app_insights.name,
)

pulumi.export('the output is:', app_insights_key)

输出为:

Outputs:
  + the output is:: {
      + app_id                             : "46470d16-bff3--b6fa8effc890"
      + application_id                     : "app-insights-temp112-gx"
      + application_type                   : "web"
      + connection_string                  : "InstrumentationKey=8418a8ce.com/"
      + creation_date                      : "2022-05-14T17:40:20.5340124+00:00"
      + disable_ip_masking                 : true
      + etag                               : "\"e800edf3-0000-0100-0000-627fe9860000\""
      + flow_type                          : "Bluefield"
      + id                                 : "/subscriptions/7bb4482f-3343-4b08"
      + ingestion_mode                     : "LogAnalytics"
      + instrumentation_key                : "8418a8cd-5700-7-3138752bd5f6"

我想访问 instrumentation_key 并尝试使用以下方式:

app_key = app_insights_key["instrumentation_key"]

但是我收到一个错误。

 RuntimeError: Event loop is closed

get_component_output return类型是Output[GetComponentResult],所以需要用apply得到它的属性:

component = insights.get_component_output(
    resource_group_name="temp_resources_group.name",
    resource_name="temp_app_insights.name",
)

app_insights_key = component.apply(lambda c: c.instrumentation_key)

Inputs/Outputs, Apply 阅读更多内容。