https://pulumi.com logo
#general
Title
# general
a

ancient-night-64850

03/19/2021, 2:53 PM
const clientConfig = pulumi.output(azure_native.authorization.getClientConfig()); var azureSubscriptionId = clientConfig.apply(config => config.subscriptionId); produced this: Error: invocation of azure-nativeauthorizationgetClientConfig returned an error: transport is closing at Object.callback (C:\source\repos\pulumi\DevOps.Infrastructure.Stacks\azure\net-core\web\node_modules\@pulumi\pulumi\runtime\invoke.js13933) What am I doing wrong?
b

bored-oyster-3147

03/19/2021, 3:27 PM
I believe
azure_native.authorization.getClientConfig()
returns something like
Output<ClientConfig>
so if you pass it to
pulumi.output(...)
you're getting
Output<Output<ClientConfig>>
which isn't what you want. this should suffice:
Copy code
var clientClient = azure_native.authorization.getClientConfig();
var subscriptionId = clientConfig.apply(c => c.subscriptionId);
Keep in mind that when you do this
subscriptionId
is still
Output<string>
so you can't just manipulate it like you would a string, it is still an output that needs to be asynchronously evaluated.
a

ancient-night-64850

03/19/2021, 3:45 PM
getting the string from the output<string> is what I am having trouble with. How would I go about that?
b

bored-oyster-3147

03/19/2021, 3:56 PM
ok my first question is - what do you need to do with it? If you need it to just pass it to another resource, you don't need to get the string out - you can just pass it to the other resource as an Output. In fact this is what you are supposed to do. If you absolutely need to get the string out, then you need to await the Output. In typescript this means converting the Output to a Promise and awaiting that.
a

ancient-night-64850

03/19/2021, 4:01 PM
the issue is when I try to pass the value to another resource I get the error invocation of azure-nativeauthorizationgetClientConfig returned an error: transport is closing
the other issue is that getClientConfig() in typescipt returns a promise off the bat
b

bored-oyster-3147

03/19/2021, 4:08 PM
ah! ok so you do in fact want to
pulumi.output(...)
the promise that
getClientConfig()
returns. Then you can
var subscriptionId = clientConfig.apply(c => c.subscriptionId);
. Then you can pass that to your resource.
Is this inside a component resource or a custom resource? If so make sure you are calling
RegisterOutputs()
at the end otherwise your pulumi execution will not wait for your promises to finish because it won't be aware of them.
It might help to share more of your code!
a

ancient-night-64850

03/19/2021, 4:12 PM
there are three lines of code: const clientConfig = pulumi.output(azure_native.authorization.getClientConfig()); var azureSubscriptionId = clientConfig.apply(config => config.subscriptionId); export const azid = "azure id: " + azureSubscriptionId;
and you'll have to forgive me, TypoeScript is not my native programming langauge
b

bored-oyster-3147

03/19/2021, 4:13 PM
export const azid = "azure id: " + azureSubscriptionId;
this line won't work because you can't concatenate types
string
and
Output<T>
. Instead you would want to:
export const azid = azureSubscriptionId.apply(x => "azure id: " + x);
a

ancient-night-64850

03/19/2021, 4:21 PM
the output is azure id: [object promise]
b

bored-oyster-3147

03/19/2021, 4:23 PM
That means that
azureSubscriptionId
was not
Output<string>
it was
Output<Promise<T>>
a

ancient-night-64850

03/19/2021, 4:25 PM
correct, that is why the pulumi,.output was needed i thought
b

bored-oyster-3147

03/19/2021, 4:28 PM
const clientConfig = azure_native.authorization.getClientConfig();
With this
clientConfig
should be
Promise<GetClientConfigResult>
const clientConfig = pulumi.output(azure_native.authorization.getClientConfig());
With this
clientConfig
should be
Output<GetClientConfigResult>
var azureSubscriptionId = clientConfig.apply(c => c.subscriptionId);
Now
azureSubscriptionId
should be
Output<string>
Which should allow you to:
export const azid = azureSubscriptionId.apply(x => "azure id: " + x);
and still have an
Output<string>
There had to have been a step that was missed if you still had a
Promise<T>
on the third line.
a

ancient-night-64850

03/19/2021, 4:58 PM
it seems that pulumi.output is actually creating UnwrappedObject<GetClientConfigResult>
b

bored-oyster-3147

03/19/2021, 5:09 PM
ok, sorry. Must be quirk of typescript. I use dotnet primarily. I couldn't find one in the azure examples but I found an example using
pulumi.output(...)
here: https://github.com/pulumi/examples/blob/4529da55208d11bc708d88b8694f92f73455500d/linode-js-webserver/index.ts and we can see here that linode GetProfile also returns `Promise<TResult>`: https://www.pulumi.com/docs/reference/pkg/linode/getprofile/ And they are just accessing the properties on that directly after that. So maybe yours should only be 2 lines? Like this:
Copy code
const clientConfig = pulumi.output(azure_native.authorization.getClientConfig());
export const azid = clientConfig.subscriptionId.apply(x => "azure id: " x);
or if
clientConfig.subscriptionId
is type
string
you might not need the
.apply(...)
a

ancient-night-64850

03/19/2021, 5:50 PM
that last example worked for me, thank you
it really only needed to be two lines
🙌 1
4 Views