I have to say that sometimes getting to a pulumi o...
# typescript
s
I have to say that sometimes getting to a pulumi output value and passing it to other things can be maddening. I am retrieving all of the usernames from an AWS IAM group to use in other places.
Copy code
const iamGroup = pulumi.output(aws.iam.getGroup({
    groupName: "myGroup",
}, { async: true }));

const usernames = iamGroup.apply(group => group.users.map(user => user.userName));
If I
export
const usernames, I see
Copy code
Outputs:
    usernames: [
        [0]: "username1"
        [1]: "username2"
        [2]: "username3"
    ]
However, later when attempting to use both
.filter
and
.map
on the
usernames
list, I get
Copy code
TSError: ⨯ Unable to compile TypeScript:
    index.ts(312,13): error TS2488: Type 'Output<string[]>' must have a '[Symbol.iterator]()' method that returns an iterator.
    index.ts(469,42): error TS2339: Property 'map' does not exist on type 'Output<string[]>'.
I have tried many variations of
.apply
but am so far unable to use the above methods or return this list from the function it is in. I have read the Inputs and Outputs doc many times but it is still painful to figure out how to make it work.
w
Did you try something like:
Copy code
const thing = usernames.apply(names => {
   return names.filter(filterFunction)
}
👀 1
The challenge (and it is a bit maddening as you said) is that usernames is not a
string[]
- it’s an
Output<string[]>
so string methods are not available to it. Therefore, you need to work within the
.apply()
block to strip that
Output
aspect and get the value as a
string[]
and then you can mess with it. In the above,
thing
will be an
Output<string[]>
again but it will contain what you want for later use.
s
Thank you @witty-candle-66007. I thought I understood using
.apply()
but sometimes it just doesn't seem to work the way I hope it will. I appreciate your explanation. It is helpful indeed. I will work with the suggestion you provided and see where I can take it.
198 Views