pulumi-azure icon indicating copy to clipboard operation
pulumi-azure copied to clipboard

GetFunctionAppHostKeysArgs should take Input<string> instead of string

Open goutham-pai-hc opened this issue 4 years ago • 2 comments

I'm trying to setup a situation in which I can provision a Function App and pull its hostkey for use in configuring some other resource in the same stack. I think GetFunctionAppHostKeys can be used to achieve this. However, it seems like the GetFunctionAppHostKeysArgs type expects strings for the resource group name and the functionApp name. This means that I cannot pass values of type Output<string> into the args.. This is problematic since a lot of values that I work with in Pulumi are of type Output<T>. Can I get some guidance on this?

goutham-pai-hc avatar Oct 27 '20 17:10 goutham-pai-hc

The typical way to handle this is to use Apply on the Output<string> and call GetFunctionAppHostKeys inside the Apply, where the value will be a string.

justinvp avatar Oct 27 '20 21:10 justinvp

I suppose that's true. Is there a concern it could get unwieldy to be using Output<T>.Apply() all over the place? Anyway, I ended up doing this to set things up:

// get node function info
var hostKeysArgs = Output
    .Tuple(functionApp.Name, resourceGroup.Name)
    .Apply(t => new GetFunctionAppHostKeysArgs()
    {
        Name = t.Item1,
        ResourceGroupName = t.Item2
    });

var hostKeys = hostKeysArgs.Apply(async (x) => await GetFunctionAppHostKeys.InvokeAsync(x));
var defaultFunctionKey = hostKeys.Apply(result => result.DefaultFunctionKey)

goutham-pai-hc avatar Oct 27 '20 22:10 goutham-pai-hc

For posterity, there's now a cleaner way to do this:

var defaultFunctionKey = GetFunctionAppHostKeys.Invoke(new()
{
    Name = functionApp.Name,
    ResourceGroupName = resourceGroup.Name,
}).Apply(result => result.DefaultFunctionKey);

justinvp avatar Nov 24 '22 00:11 justinvp