hi all, in Terraform, we can set output to expose ...
# general
s
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
If by module you mean a different part of your project code then you can simply refer to this attribute.
m
If you are writing a ComponentResource, you expose them as properties of the class.
p
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
s
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
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
is it possible to refer to the output without initializing an instance of MyResource?
p
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
yes - I should have created a child resource in my example to make this clear - thanks Jakub
s
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
@square-coat-62279 Can you post some code showing what you are trying to do? May make it clearer
p
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
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
That sounds about right 🙂
and there’s no need to feel sorry!