https://pulumi.com logo
Title
l

little-market-63455

05/19/2021, 3:03 PM
Hi everyone, started recently with Pulumi and went over most of the articles I am facing a couple of problems, probably due to using TypeScript and learning it along with Pulumi at the same time With that being said, I don't think the problem is with TypeScript per say but with my understanding on how to properly handle
Promise<T>
s, `Input<T>`s and
Output<s>
1. If I am builI am building a
ComponentResource
which needs some information about an IAM user (which is already created) 2. To fetch information about that user, I can use
aws.iam.getUser
which returns a
Promise<GetUserResult>
3. Now, I don't know how to properly deal with that Promise 4. On one hand, I could make the ComponentResrouce accept
Input<GetUserResult>
and wrap my Promise with an
Output<T>
then pass it on. This should trigger dependency tracking according to my understanding. Is this really the way to go? 5. Or I could
await
the promise and get the result then pass it as a regular object but then I have to enable top-level awaits or perhaps use
then
? Sorry for the confusion, trying to learn and apply too many things at the same time and I appreciate your help.
b

billowy-army-68599

05/19/2021, 3:08 PM
@little-market-63455 this doesn't directly answer your question, but I recently wrote this which may help to understand some of the things you're saying: https://www.leebriggs.co.uk/blog/2021/05/09/pulumi-apply.html
🔥 1
👀 2
the short answer is: if you're building an IAM role (which accepts a string) you can use
aws.iam.getUser
then use an
apply()
to build the policy document string
l

little-market-63455

05/19/2021, 3:15 PM
I will be sure to read that @billowy-army-68599. Thank you
I am kinda using multiple properties from
GetUserResult
eventually to build different resources. So according to your suggestion I should be accepting a
Input<GetUserResult>
on the inside of the component?
b

billowy-army-68599

05/19/2021, 3:25 PM
no, you would use
pulumi.all
- I can try build an example, hold on
which properties are you using from
GetUserResult
?
l

little-market-63455

05/19/2021, 3:32 PM
the
Arn
and the
UserName
b

billowy-army-68599

05/19/2021, 3:39 PM
@little-market-63455 as I'm building this I'm realising, what are you passing those values to?
l

little-market-63455

05/19/2021, 3:40 PM
to the constructor of the
ComponentResource
eventually they propogate all the way to properties on native cloud resources like roles or access keys and so on
b

billowy-army-68599

05/19/2021, 3:50 PM
sorry my question isn't clear, what AWS resources are you trying to populate in your component resource so I can show you how I'd generally do it. Most of the resources I'm looking up take inputs
l

little-market-63455

05/19/2021, 3:54 PM
I am creating an
aws.iam.Policy
where the
Resouce
array includes the ARN of the user Another usage is when calling the AWS APIs with the user's name to get their access key
b

billowy-army-68599

05/19/2021, 3:55 PM
got it, working on an example now
l

little-market-63455

05/19/2021, 3:56 PM
Appreciate it so much sir, I am reading your article atm
Well written 👍
b

billowy-army-68599

05/19/2021, 4:35 PM
Okay, here's the example: https://github.com/jaxxstorm/pulumi-examples/tree/main/typescript/aws/existing-iam-user I tried to show some of the different mechanisms you can use, it may not exactly suit your use case, but this is how I'd manage this
basically: make your input types primitive types where needed
you'll see here: https://github.com/jaxxstorm/pulumi-examples/blob/main/typescript/aws/existing-iam-user/userrole.ts#L48 I'm using
pulumi.output
but I only use one of the paramaters, that's mainly to show you what's possible:
l

little-market-63455

05/19/2021, 6:05 PM
I see. I should have mentioned earlier but I was trying to modify this example from a Pulumi blog post. You can see the author passing a
user
type in and I thought initially I would pass the equivalent But I also understand the way you did. Thank you kindly for your help
l

little-cartoon-10569

05/19/2021, 8:51 PM
In this example, the
user
variable is a Pulumi resource, so you don't need to use
getUser
. You can pass the id of the user directly from the user variable to other Pulumi resource constructors.
You can skip the process of retrieving the user's properties from AWS, since Pulumi has already done that and populated the aws.iam.User object with them. Since you're passing the values into a policy document, there is an extra step involving interpolation.
l

little-market-63455

05/20/2021, 7:36 AM
Correct but I have modified the example and the user already exists for me, I don't want Pulumi to create it
@billowy-army-68599 If I was to pass the output to helper functions, I would assume that passing
Output<GetUserResult>
should work?
I guess I feel the other alternative with all the
applies
is a bit unreadable but that's probably more idiomatic from what I feel now
l

little-cartoon-10569

05/20/2021, 7:57 PM
Even if the user already exists, you can import it. Since Pulumi is a declarative state management tool, it won't recreate it. The user will be in Pulumi state and usable in the normal way.