https://pulumi.com logo
Title
b

broad-dog-22463

03/09/2021, 3:24 PM
@tall-librarian-49374 would love your thoughts on that ☝️ I was on a call with @worried-knife-31967 and could see some weird behaviour
t

tall-librarian-49374

03/09/2021, 3:27 PM
I can’t remember trying this but I can’t see why it shouldn’t work. Any details on the weird behaviour?
b

broad-dog-22463

03/09/2021, 3:38 PM
@worried-knife-31967 wanna post the gist here?
for clarity, it will only get as far as
got 5
and that's intermittent.
t

tall-librarian-49374

03/09/2021, 4:07 PM
And what happens then? Does the program succeed/fail? Do you get the output?
b

bored-oyster-3147

03/09/2021, 4:07 PM
Odd that it makes it past the first await but not the second?
w

worried-knife-31967

03/09/2021, 4:13 PM
it didn't actually create the key, but now it won't run it as the resource has been created. If I change the inputs (i.e. the key name and value) it doesn't recreate the resource either
t

tall-librarian-49374

03/09/2021, 4:15 PM
Which resource? This should run regardless of whether a resource is already created or not.
Are you assigning the
Key
to stack outputs?
Try adding this to your consturctor
base.RegisterOutputs(new Dictionary<string, object?> { { "Key", Key }});
b

bored-oyster-3147

03/09/2021, 4:20 PM
Also I don't know that this is affecting anything, especially since you're only getting to
got 5
, but it's throwing me off a little bit that line 61 of the gist is assigning to
this.Key
when the constructor already did that
w

worried-knife-31967

03/09/2021, 4:47 PM
A combination of all the above seems to have done it 😄
🙌 1
one thing though... it seems that it's runs before I tell it to apply...
I'm assuming I need to add an if statement around it as a "DryRun"?
b

bored-oyster-3147

03/09/2021, 4:49 PM
so
RegisterOutputs
internally adds the task to a collection of tasks to be awaited. the issue before was your task wasn't being awaited so the program was exitting before it could finish. Also when you pass
CreateAsync
that task starts running immediately, which is why you are seeing it run before you apply
w

worried-knife-31967

03/09/2021, 4:54 PM
That makes sense. So how do I stop the webrequest from running as part of the first phase, and make it run only after the yes part?
b

bored-oyster-3147

03/09/2021, 4:58 PM
I think you are correct that checking
IsDryRun
will do that for you
t

tall-librarian-49374

03/09/2021, 5:01 PM
args.Name shouldn’t resolve until the function app is created, if I read the code correctly
w

worried-knife-31967

03/09/2021, 5:02 PM
it's more that it's running everytime I do
pulumi up
so if the key gets cycled, it would update that before the other things
b

bored-oyster-3147

03/09/2021, 5:07 PM
As the code currently exists you will create a new key on every deploy. I think what you might be looking for is a
dynamic provider
which would handle not creating if it already exists, updating it, etc.. unfortunately not supported in .NET right now
ComponentResource
is mostly meant to be used to encapsulate the deployment of a logical grouping of cloud resources. But you're trying to give pulumi the ability to manage/provision a custom resource (your function key) so you want a provider
t

tall-librarian-49374

03/09/2021, 5:21 PM
Agreed. This is a custom resource-level thing. In theory, this could be a custom resource inside the provider, or in a separate library, implemented once and generated for all languages. Obviously, it’s a larger commitment, but the tech is there.
w

worried-knife-31967

03/09/2021, 5:25 PM
I've done this for now...
if (Pulumi.Deployment.Instance.IsDryRun)
        {
            var dryRunResponse = await httpClient.GetAsync(new Uri($"/admin/host/keys/{keyName}", UriKind.Relative));
            if (dryRunResponse.IsSuccessStatusCode)
            {
                var getkeyresponse = JsonSerializer.Deserialize<GetKeyResponse>(await dryRunResponse.Content.ReadAsStringAsync());
                if (keyValue == getkeyresponse.Value)
                    return keyValue;
            }

            return "";
        }
I'm assuming that dryrun is the bit before someone clicks "yes"
I figured
CustomResource
was what was required for this... Dynamic Provider might be the one I suppose. I'm happy to put some effort into it... I'm going to drop that solution into a blog later as it's required for getting functions into an Azure API Manager.
b

broad-dog-22463

03/09/2021, 6:09 PM
yes, DryRun is a preview