pulumi / pulumi-azure-native

Azure Native Provider
Apache License 2.0
129 stars 35 forks source link

Provider should handle asynchronous completion of invokes #1735

Open henworth opened 2 years ago

henworth commented 2 years ago

What happened?

When trying to query for a Virtual Network Gateway's advertised routes, the response seems to be not handled properly.

Using the getVirtualNetworkGatewayAdvertisedRoutes() function this error is returned:

Exception: invoke of azure-native:network:getVirtualNetworkGatewayAdvertisedRoutes failed: invocation of azure native:network:getVirtualNetworkGatewayAdvertisedRoutes returned an error: request failed /subscriptions/REDACTED/resourceGroups/example/providers/Microsoft.Network/virtualNetworkGateways/example/getAdvertisedRoutes: autorest/azure: Service returned an error. Status=202 Code="Unknown" Message="Unknown service error" Details=[{"HttpResponse.Body":"null"}]

Steps to reproduce

Use the getVirtualNetworkGatewayAdvertisedRoutes() function with a Resource Group name and Virtual Network Gateway name (optionally a peer ip) and the above error is returned.

azure.network.get_virtual_network_gateway_advertised_routes(
    virtual_network_gateway_name="example",
    resource_group_name="example",
    peer="169.254.21.1",
)

Expected Behavior

An output of the advertised routes. The API specs show that this endpoint returns both a HTTP 202 status and an empty body upon acceptance of the command, and that the operation will be handled asynchronously. In the returned error string, both of these values are present.

https://docs.microsoft.com/en-us/rest/api/network-gateway/virtual-network-gateways/get-advertised-routes

Actual Behavior

This error message was returned:

error: Program failed with an unhandled exception:
error: Traceback (most recent call last):
  File "/usr/local/bin/pulumi-language-python-exec", line 107, in <module>
    loop.run_until_complete(coro)
  File "/usr/local/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 647, in run_until_complete
    return future.result()
  File "/Users/henworth/code/pulumi/aws-azure-peering/venv/lib/python3.9/site-packages/pulumi/runtime/stack.py", line 126, in run_in_stack
    await run_pulumi_func(lambda: Stack(func))
  File "/Users/henworth/code/pulumi/aws-azure-peering/venv/lib/python3.9/site-packages/pulumi/runtime/stack.py", line 49, in run_pulumi_func
    func()
  File "/Users/henworth/code/pulumi/aws-azure-peering/venv/lib/python3.9/site-packages/pulumi/runtime/stack.py", line 126, in <lambda>
    await run_pulumi_func(lambda: Stack(func))
  File "/Users/henworth/code/pulumi/aws-azure-peering/venv/lib/python3.9/site-packages/pulumi/runtime/stack.py", line 149, in __init__
    func()
  File "/usr/local/bin/pulumi-language-python-exec", line 106, in <lambda>
    coro = pulumi.runtime.run_in_stack(lambda: runpy.run_path(args.PROGRAM, run_name='__main__'))
  File "/usr/local/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 285, in run_path
    return _run_code(code, mod_globals, init_globals,
  File "/usr/local/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/Users/henworth/code/pulumi/aws-azure-peering/./__main__.py", line 393, in <module>
    azure.network.get_virtual_network_gateway_advertised_routes(
  File "/Users/henworth/code/pulumi/aws-azure-peering/venv/lib/python3.9/site-packages/pulumi_azure_native/network/get_virtual_network_gateway_advertised_routes.py", line 68, in get_virtual_network_gateway_advertised_routes
    __ret__ = pulumi.runtime.invoke('azure-native:network:getVirtualNetworkGatewayAdvertisedRoutes', __args__, opts=opts, typ=GetVirtualNetworkGatewayAdvertisedRoutesResult).value
  File "/Users/henworth/code/pulumi/aws-azure-peering/venv/lib/python3.9/site-packages/pulumi/runtime/invoke.py", line 166, in invoke
    raise invoke_error
Exception: invoke of azure-native:network:getVirtualNetworkGatewayAdvertisedRoutes failed: invocation of azure native:network:getVirtualNetworkGatewayAdvertisedRoutes returned an error: request failed /subscriptions/REDACTED/resourceGroups/example/providers/Microsoft.Network/virtualNetworkGateways/example/getAdvertisedRoutes: autorest/azure: Service returned an error. Status=202 Code="Unknown" Message="Unknown service error" Details=[{"HttpResponse.Body":"null"}]

error: an unhandled error occurred: Program exited with non-zero exit code: 1

Versions used

CLI
Version      3.33.1
Go Version   go1.17.10
Go Compiler  gc

Plugins
NAME          VERSION
aws           5.4.0
azure-native  1.64.0
python        unknown
random        4.7.0

Host
OS       darwin
Version  12.3.1
Arch     x86_64

This project is written in python (/usr/local/bin/python3 v3.9.12)

I also tried with v20210801 of the API.

Additional context

When using the Azure CLI equivalent command, the expected list of routes is returned:

az network vnet-gateway list-bgp-peer-status --resource-group example --name example --peer 169.254.22.1
{
  "value": [
    {
      "asPath": "65000",
      "localAddress": "10.152.1.4",
      "network": "10.152.0.0/16",
      "nextHop": "169.254.22.2",
      "origin": "Igp",
      "sourcePeer": null,
      "weight": 0
    },
    {
      "asPath": "65000-64512",
      "localAddress": "10.152.1.4",
      "network": "172.31.0.0/16",
      "nextHop": "169.254.22.2",
      "origin": "Igp",
      "sourcePeer": null,
      "weight": 0
    }
  ]
}

This same behavior also occurs with the getVirtualNetworkGatewayBgpPeerStatus() function and likely others (especially if they return 202s) but I have only tested these two functions.

Contributing

Vote on this issue by adding a 👍 reaction. To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

viveklak commented 2 years ago

Thanks for opening the issue @henworth.

I don't fully grok the semantics of the API from the docs in the case of a 202 response. Typically in other posts this returns a polling location in the Location header and I assume the same is the case here. That said, the provider's current invoke support doesn't handle asynchronous responses. I have updated the issue title and added this to our prioritized backlog.