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

square-coat-62279

11/10/2021, 10:18 AM
hi all, in Terraform, we can set output to expose certain attribute of the resource of a module, so that other module can refer to it directly when creating other resources that depends on that attribute, how can I do that in Pulumi?
p

prehistoric-activity-61023

11/10/2021, 10:21 AM
If by module you mean a different part of your project code then you can simply refer to this attribute.
m

miniature-king-36473

11/10/2021, 10:21 AM
If you are writing a ComponentResource, you expose them as properties of the class.
p

prehistoric-activity-61023

11/10/2021, 10:21 AM
If you want to export the value so that other Pulumi project can use it, you have to export it as an output and use stack references.
e

enough-mouse-43206

11/10/2021, 12:37 PM
s

square-coat-62279

11/10/2021, 1:29 PM
how do I refer to registerOuputs from another class?
it's within the same stack, say for example I have a service account created in IAM class and I have another resource in a different class that requires the email address of that IAM account, what should I do?
m

miniature-king-36473

11/10/2021, 1:59 PM
in that case you are better defining properties for the class. e.g.
Copy code
export class MyResource extends ComponentResource {
  readonly myOutput: Output<string>;
  constructor(name: string, args: any, opts?: ResourceOptions) {
   super("components:MyResource", name, args, opts);
   this.myOutput = "something";
  }
}
You can then just reference the properties when you use the Resource
Copy code
const resource = new MyResource("my_resource",{});

const output = resource.myOutput
✔️ 1
s

square-coat-62279

11/10/2021, 2:13 PM
is it possible to refer to the output without initializing an instance of MyResource?
p

prehistoric-activity-61023

11/10/2021, 2:19 PM
Output exists only because the instance of MyResource is created.
If you know the value before that time, it means it’s not an actual (variable) output and it can be live unrelated to the given resource and be declared as constant.
m

miniature-king-36473

11/10/2021, 3:00 PM
yes - I should have created a child resource in my example to make this clear - thanks Jakub
s

square-coat-62279

11/11/2021, 6:19 AM
thanks @prehistoric-activity-61023 and @miniature-king-36473 Not sure if this makes sense, basically, coming back to the use case, I got the idea of exposing the email of the IAM account as a property in the IAM class, but what do I need to do at the other dependent class? I imported the IAM class and tried to refer to the email ID of the IAM account created by the IAM class but not sure how I can do that without instantiating the IAM class in the dependent class
m

miniature-king-36473

11/11/2021, 8:59 AM
@square-coat-62279 Can you post some code showing what you are trying to do? May make it clearer
p

prehistoric-activity-61023

11/12/2021, 7:26 AM
also please share what programming language you currently use
As you said, it’s impossible to get the email just by importing the class (class doesn’t have any data on it, object does). You have to share the created object through some kind of dependency injection.
s

square-coat-62279

11/12/2021, 8:32 AM
thanks all, I think I managed to figure out the problem, i.e. I need to expose the email in the IAM class and then parse it into the other class in the index.ts; I can't refer to the email (or property of IAM class) in another class without instantiate it. Sorry for this noob question, newbie to OOP here 😳
p

prehistoric-activity-61023

11/12/2021, 8:38 AM
That sounds about right 🙂
and there’s no need to feel sorry!