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

Time:05-16

I created an Azure App Insights with Pulumi and with GetComponnectOutput I received the output like the below:

Sample Code:

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)

The Output is:

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"

I wanna access to instrumentation_key and try to use the below way:

app_key = app_insights_key["instrumentation_key"]

But I received an error.

 RuntimeError: Event loop is closed

CodePudding user response:

get_component_output return type is Output[GetComponentResult], so you need to use apply to get its property:

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)

Read more in Inputs/Outputs, Apply.

  • Related