https://pulumi.com logo
#azure
Title
# azure
m

miniature-leather-70472

04/13/2021, 10:21 AM
I'm attempting to create a method to call the Azure Rest API directly following this example https://github.com/pulumi/pulumi-azure-native/issues/601 by @tall-librarian-49374 it used to work fine, but now it seems that it's stopping at this line:
Copy code
var token = await Pulumi.AzureNative.Authorization.GetClientToken.InvokeAsync();
I don't get any error, it just does not proceed past this line in my async method. Any ideas why, or what I can do to try and find the issue? I am calling this async method from the main Pulumi code using getawaiter, so my understanding is that it should wait.
t

tall-librarian-49374

04/13/2021, 10:30 AM
I am calling this async method from the main Pulumi code using getawaiter,
GetAwaiter doesn’t block on its own. Could you show your code?
m

miniature-leather-70472

04/13/2021, 10:35 AM
This is the method:
Copy code
static async Task<string> SetIpGroupIp(string ipGroupId, string ip)
        {
          
                var ipGroupResourceGroup = ipGroupId.Split("/")[4];
                var ipGroupName = ipGroupId.Split("/")[8];
                var token = await Pulumi.AzureNative.Authorization.GetClientToken.InvokeAsync();
                var networkClient =
                    new NetworkManagementClient(new TokenCredentials(new StringTokenProvider(token.Token, "Bearer")))
                    {
                        SubscriptionId = ipGroupId.Split("/")[2]
                    };
                var ipGroup = (await networkClient.IpGroups.GetWithHttpMessagesAsync(ipGroupResourceGroup, ipGroupName))
                    .Body;
                Log.Warn(ipGroup.IpAddresses[0]);
                if (!ipGroup.IpAddresses.Contains(ip))
                {
                    ipGroup.IpAddresses.Add(ip);
                    await networkClient.IpGroups.CreateOrUpdateWithHttpMessagesAsync(ipGroupResourceGroup, ipGroupName,
                        ipGroup);
                }
                return ip;
        }
and this is how it is called
Copy code
if (!Pulumi.Deployment.Instance.IsDryRun)
        {
            aksIp.Apply(ip =>
            {
                var aksip = SetIpGroupIp(config.Require("AKSIpGroup"), ip).GetAwaiter().GetResult();
                return aksip;
            });
        }
t

tall-librarian-49374

04/13/2021, 10:37 AM
Can you try returning the result of
Apply
as a stack output?
m

miniature-leather-70472

04/13/2021, 11:01 AM
Yeah looks like that may have been it
Thanks
3 Views