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

shy-microphone-28807

01/10/2020, 9:19 PM
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

astonishing-cartoon-37000

01/10/2020, 9:27 PM
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

shy-microphone-28807

01/10/2020, 9:30 PM
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

astonishing-cartoon-37000

01/10/2020, 9:41 PM
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

shy-microphone-28807

01/10/2020, 9:42 PM
hm
a

astonishing-cartoon-37000

01/10/2020, 9:43 PM
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

acoustic-florist-12628

01/10/2020, 10:50 PM
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

shy-microphone-28807

01/13/2020, 9:22 PM
Thanks @acoustic-florist-12628 looks like im still missing something though