pulumi / pulumi-azure-native

Azure Native Provider
Apache License 2.0
126 stars 33 forks source link

Can't retrieve AVD HostPool registration token #3317

Closed DjordjeTosic closed 3 months ago

DjordjeTosic commented 3 months ago

What happened?

Hello, I'm trying to join client machines to AVD host pool, for those purposes I created AVD Host Pool and registration token with pulumi python. But I'm facing with issue that I can't read token from AVD Host Pool, even though token is created and it is visible on Azure portal.

Example

def create_avd(resource_group, provider, dt_map):
    host_pool = azure_native.desktopvirtualization.HostPool(
        resource_name=f"vdpool-{dt_map.project_name}-{dt_map.name}",
        resource_group_name=resource_group.name,
        location=resource_group.location,
        host_pool_type="Pooled",
        load_balancer_type="BreadthFirst",
        max_session_limit=3,
        preferred_app_group_type="Desktop",
        custom_rdp_property="drivestoredirect:s:;audiomode:i:0;videoplaybackmode:i:1;redirectclipboard:i:0;redirectprinters:i:0;devicestoredirect:s:;redirectcomports:i:0;redirectsmartcards:i:0;usbdevicestoredirect:s:;enablecredsspsupport:i:1;use multimon:i:1;audiocapturemode:i:0;encode redirected video capture:i:1;redirected video capture encoding quality:i:0;camerastoredirect:s:",
        registration_info=azure_native.desktopvirtualization.RegistrationInfoArgs(
            expiration_time=(datetime.utcnow() + timedelta(hours=2)
                             ).isoformat() + 'Z',  # 2h from now
            registration_token_operation=azure_native.desktopvirtualization.RegistrationTokenOperation.UPDATE
        ),
        opts=pulumi.ResourceOptions(
            provider=provider)
    ) 
    host_pool.registration_info.apply(lambda registration_info: print(f"{registration_info.token}"))

Output of pulumi about

Pulumi always print "None" value, no matter when I call this output of HostPool

Additional context

No response

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).

thomas11 commented 3 months ago

Hi @DjordjeTosic, thank you for reporting this. Your code looks correct at first glance.

Would you be able to obtain verbose logs? For instance, like this: pulumi up --debug -v=9 --skip-preview --yes --logflow --logtostderr.

The HTTP requests to Azure and the responses are the interesting part, they should be towards the end. You might want to redact your subscription.

DjordjeTosic commented 3 months ago

Hi @thomas11,

I just have ran command that you sent to me, and i received a bit confusing output. In output i can see that token is created and its value, but also in some parts of output i saw that HTTP Response is "Empty body", or just expiration_time and registration_token_operation values.

I will attach output document to the conversation, so maybe you can take a look at it and see what is the problem, you are, for sure, more familiar with this then me :) out.txt

And just to mention, i don't have this problem when I'm using pulumi_azure module.

thomas11 commented 3 months ago

I understand the problem now. It's a long-standing bug in Azure's AVD service. When you create a host pool, the registration info is returned in the response. But when you GET a host pool, registration info is null, even though the docs state that both responses should be the same.

We'll need to discuss how to fix this.

thomas11 commented 3 months ago

Based on the discussion on the open Azure issue, it seems like the bug is rather that the token is in the PUT response, not that it's missing in the GET response. Since it's a secret, although not properly marked as such, it should be retrieved separately.

I just merged a PR #3330 that adds the corresponding Pulumi function, get_host_pool_registration_token. We'll release it shortly as a patch release.

DjordjeTosic commented 3 months ago

Great! Thank you on quick response and resolving this issue.