Hi! I imported a Vpc as part of another Custom Obj...
# typescript
a
Hi! I imported a Vpc as part of another Custom Object A. I want to use this vpn (now a property of my object A) as input to other object. is it possible?
l
Yes, you can pass the VPC to the constructor of another custom resource. You can also pass it between projects and stacks as stack outputs, though in general it is preferred to use simpler values (strings, etc.) as stack outputs.
If you're using the Vpc in two classes in the same project, then just pass it around like any other value.
a
Yes, but I defined inside Object custom resource a properti Output<aws.ec2.vpc> , and when I try to pass as argument this property, it is read as "promise"
l
It probably shouldn't be in an Output. All its output properties are Outputs, the Vpc itself shouldn't need to be an Output. Would you like to share some code?
c
Here is an example vpc built in typescript and then being imported into ecs that you can view.
a
@little-cartoon-10569 yes, it is my example code
Copy code
export class ModuleA extends pulumi.ComponentResource {

    public vpc: pulumi.Output<awsx.ec2.Vpc>;
    constructor(name:string, args: customType,opts?: pulumi.CustomResourceOptions){
     
        ...
        ...
    }

}
Copy code
const Module1 = new ModuleA(name, args, {});

// this should receive vpc arguments of Module 1
const Module2 = new ModuleB(name, {
    vpc: Module1.vpc
})
l
Can we see the code that present the Vpc as an output? Maybe we can keep it as a Vpc?
Essentially: why is Module1.vpc an output?
a
@little-cartoon-10569 because vpc is the result of an import of an existing vpc, which I want to use in my main program or as an input argument to another module
l
Importing a VPC should give you a Vpc, not an Output<Vpc>. Can we see that import code?
Did you use
pulumi import
, which results in a
Vpc
? Or
new aws.ec2.Vpc("x", { ... }, { import: "vpcid" })
?
If you used a StackReference from another stack, then you'd get an Output<Vpc>, but generally the way to go there is to pass the vpcId between stacks, not the Vpc itself.
It should be possible to arrange your projects and stacks so that you need the Vpc object in exactly one stack only.
a
yes, I share with you part of my code ...
Copy code
export class ModuleA extends pulumi.ComponentResource {

    public vpc: awsx.ec2.Vpc;
    constructor(name:string, args: customType,opts?: pulumi.CustomResourceOptions){
        
        const awsVpc = new aws.ec2.vpc("name",{
            cidrBlock:"cidr",
            subnets: ["subnet1","subnet2"],
        },{
            import: "vpc-id12321313"
        })
        this.vpc = new awsx.ec2.vpc("name",{
            vpc: awsVpc
        })
        ...
        ...
    }

}
then in my index.ts i want to do :
Copy code
const Module1 = new ModuleA(name, args, {});
    // this should receive vpc arguments of Module 1
    const Module2 = new ModuleB(name, {
        vpc: Module1.vpc
    })
l
I can't see why vpc is an output. In the code you have there, Module1.vpc is an awsx.ec2.Vpc, not a pulumi.Output<awsx.ec2.Vpc>. That's fine, leave it that way. Everything will work.
a
ok, thanks for your help!