const clientConfig = pulumi.output(azure_native.au...
# general
a
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
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
getting the string from the output<string> is what I am having trouble with. How would I go about that?
b
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
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
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
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
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
the output is azure id: [object promise]
b
That means that
azureSubscriptionId
was not
Output<string>
it was
Output<Promise<T>>
a
correct, that is why the pulumi,.output was needed i thought
b
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
it seems that pulumi.output is actually creating UnwrappedObject<GetClientConfigResult>
b
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
that last example worked for me, thank you
it really only needed to be two lines
🙌 1