if I have a list of aws account outputs and want t...
# general
s
if I have a list of aws account outputs and want to map that to an array of account IDs, is
pulumi.all
the right way to do that?
a
if it's only 1 variable of type
pulumi.Output<awsAccounts>[]
then I think you can simply psuedo-js-code
Copy code
const awsAccounts = Pulumi.Output<aswAccounts>[]
const accountIds = awsAccounts.map(account => account.apply(val => val.id))
idk if it's "right way to do it"
but it still would be a list of
pulumi.Output<ids>
s
im trying to put it in an input that has type
string[]
but cannot figure out how to accomplish that and keep typescript happy
const sourceIds = pulumi.all([account, otherAccount]).apply(accounts => accounts.map(a => a.id.get())).get()
makes the compiler happy but still need to do a test run, it seems like there should be a simpler way to do that
a
oh wait
.get()
says : This function is only callable in code that runs in the cloud post-deployment.
Copy code
This function is only callable in code that runs in the cloud post-deployment. At this point all Output values will be known and can be safely retrieved. During pulumi deployment or preview execution this must not be called
s
hm
a
using the value inside the
.apply()
has worked for me in the past, but I feel that it isn't a good pattern. None of it will show in preview
lmk if you figure something out! I have struggled with getting value out of outputs too.
a
if you have 3 pulumi Output<string> variables var1, var2, and var3, then pulumi.all([var1, var2, var3]) will return an Output<any[]>. You can then cast that return value to an Output<string[]>, and within later apply() calls TypeScript will treat the value as a string[] type containing the 3 strings from var1, var2, and var3. Outside of apply(), all(), and similar pulumi methods, pulumi Output types cannot be "unwrapped". So if you want to take 3 separate pulumi Outputs and compose them together into 1 pulumi Output, then utilize the values in that Output, pulumi.all followed by pulumi.apply is the most natural choice. Within the apply, the value will be of type string[] (as long as you cast the type as described above).
s
Thanks @acoustic-florist-12628 looks like im still missing something though