This message was deleted.
# general
s
This message was deleted.
t
I can’t remember trying this but I can’t see why it shouldn’t work. Any details on the weird behaviour?
b
@worried-knife-31967 wanna post the gist here?
for clarity, it will only get as far as
got 5
and that's intermittent.
t
And what happens then? Does the program succeed/fail? Do you get the output?
b
Odd that it makes it past the first await but not the second?
w
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
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
Copy code
base.RegisterOutputs(new Dictionary<string, object?> { { "Key", Key }});
b
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
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
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
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
I think you are correct that checking
IsDryRun
will do that for you
t
args.Name shouldn’t resolve until the function app is created, if I read the code correctly
w
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
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
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
I've done this for now...
Copy code
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
yes, DryRun is a preview