https://pulumi.com logo
#typescript
Title
# typescript
a

adamant-translator-31969

01/18/2021, 7:42 PM
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

little-cartoon-10569

01/18/2021, 8:27 PM
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

adamant-translator-31969

01/18/2021, 8:47 PM
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

little-cartoon-10569

01/18/2021, 8:53 PM
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

cool-fireman-90027

01/19/2021, 12:55 PM
Here is an example vpc built in typescript and then being imported into ecs that you can view.
a

adamant-translator-31969

01/19/2021, 1:14 PM
@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

little-cartoon-10569

01/19/2021, 9:50 PM
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

adamant-translator-31969

01/20/2021, 2:07 PM
@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

little-cartoon-10569

01/20/2021, 8:30 PM
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

adamant-translator-31969

01/22/2021, 2:03 PM
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

little-cartoon-10569

01/23/2021, 1:09 AM
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

adamant-translator-31969

01/25/2021, 12:01 PM
ok, thanks for your help!