Is there a way to turn `pulumi.Output*<*string[...
# general
f
Is there a way to turn
pulumi.Output*<*string[]*>*
into a
pulumi.Input*<*string*>[]*
?
w
There is actually no way to do this. The latter implies that the length of the array is known promptly, whereas the former in general the length of the array is only known some time in the future. So there is no way to turn the former into the latter (it contains strictly less information). The example you have below returns a
q: Output<Output<string>[]>
which is probably not what you want. If you can share the context of how you are trying to use this - there is frequently an alternative way to structure things that can avoid the need to know the length of the array promptly.
f
Yeah the example I provided returned the type you mentioned but it works, I assume pulumi just flattens it in the end. That being said, it works even without me doing anything with it. What I am doing is using zone.nameservers as an argument to records on
aws.route53.Record
It expects
Output<string>[]
while I have
Output<string[]>
Can I assume in the future that they will work interchangeably or is this just a fluke?
Yeah I know of the types I was just not sure why
Output<string[]>
would work with something that expects
Input<string>[]
Notice the distinction, one is a promise of Array<String> the other is Array of Promises containing String.
w
The
records
input is of type
Input<Input<string>[]>
which accepts an
Output<string[]>
. https://github.com/pulumi/pulumi-aws/blob/master/sdk/nodejs/route53/record.ts#L381
Note that there is an extra
Input<>
on the outside. That is why.
f
Yeah but they are different types. Not referring to input/output because I am sure Pulumi tackles that. I am referring to the fact that one is an Array of Strings the other is an Array of Promises.
Yeah but as I said, it’s not clear what kind of type implicit conversion pulumi does there. I mean from a Type safety PoV An Array of Promises is significantly different than an Array of Strings
w
An input is a T or a Promise<T> or an Output<T>.
It’s just a union of these three types - any of them is allowed.
f
Right, but there is a distinction here, I am not sure if I am explaining it properly. You got something that expects
Array<Promise<String>>
But I hand it an
Promise<Array<String>
They are different, but I am sure you tackle it somehow, but from a type safety point of view, I don’t think it’s sound.
I guess Pulumi just flattens until there is no more promises and takes the values.
I wasn’t sure if it was a fluke or not.
I mean it worked.
w
The key thing is the outer Input (and that there are two of them). There is no sense in which it expects a
Array<Promise<string>>
. (Technically that is one valid thing it accepts, but it accepts many others including
Promise<Array<string>>
. If you expand out both Inputs into each of the three options in the Union you get a total of 9 options, one of them is exactly the thing you have.
Just to restate - they type of the input here is
Input<Input<string>[]>
f
Alright, thanks for taking your time explaining it, appreciate it.
👍 1
Sorry to bother you again, is there a way I can get access to the value of a Input? Say I create a IAM user and want its access token and keys to add to a Kubernetes Secret/Volume. Pulumi makes it so easy to do that. The issue with regular k8 ( I am not using k8x) I can’t get access to the value.
We’re not going to use k8 crosswalk because we want to remain as close as we can with manifest files while still using typescript. It’s actually nicer for debugging/lookup purposes.
w
You should be able to pass an Input into a Kubernetes resource in Pulumi. Can you share an example of what you are trying?
f
So any Pulumi promise type (Input/Output) will be flatten to its T when applied to any kubernetes manifest spec?