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

boundless-yacht-14192

03/01/2024, 5:57 AM
Hey Pulumi people, an issue in converting
pulumi.Output<awsx.ec2.Vpc>
to
awsx.ec2.Vpc
. I use
stackRefeence
to bring a AWS Vpc object to another project like this:
Copy code
const mainVpcOutput: pulumi.Output<awsx.ec2.Vpc> = stackRef.getOutput("mainVpc") as
                                              pulumi.Output<awsx.ec2.Vpc>;
Then, I need to convert it to an
awsx.ec2.Vpc
object because this is the type that I will pass as an argument to other resources. So, I do this to convert it:
Copy code
let mainVpc: awsx.ec2.Vpc;
mainVpcOutput.apply(vpc => {
    mainVpc = vpc; 
});
But, when using the mainVpc variable, later on, it gives this error:
Variable 'mainVpc' is used before being assigned.ts
Any solution to properly convert the pulumi.Output to Vpc?
s

salmon-account-74572

03/01/2024, 6:16 AM
I’m not sure what you’re trying to do, but you’re probably better off using properties of the VPC across stack references (i.e., the VPC ID, the subnets, etc.).
b

boundless-yacht-14192

03/01/2024, 6:22 AM
Yes, that was my first solution, but I'll refer to several properties of the vpc in the other ComponentResources, so I thought maybe better to pass the whole Vpc to them.