Hello, I have a problem using vpc created in other...
# general
s
Hello, I have a problem using vpc created in other project. Inside project
A
I created a VPC like this:
Copy code
const vpc = new awsx.ec2.Vpc('project-a-vpc', { numberOfAvailabilityZones: 2 });
module.exports = { vpcId: vpc.id };
and inside project
B
I created Vpc resource pointing to existing Vpc like this:
Copy code
const stack = new pulumi.StackReference('myorg/stack-a/main');
const vpcId = mainStack.getOutput('vpcId');
const vpc = new awsx.ec2.Vpc('vpc', { vpcId });
But when I try to use the publicSubnetIds property it says it is an empty array, but inside stack A, it is not empty.
Copy code
const dbSubnetGroup = new aws.rds.SubnetGroup('db-subnet-group', {
  subnetIds: vpc.publicSubnetIds
});
Any clue how can I refer to an existing vpc and use all its properties as I would inside project A? Also, if I go with this solution of getting existing vpc:
Copy code
const vpc = aws.ec2.Vpc.get('vpc', vpcId);
i dont have
publicSubnetIds
property at all.
1
w
In project B you can use https://www.pulumi.com/registry/packages/aws/api-docs/ec2/getsubnets/ to get the subnets for the VPC using the
vpc-id
in the filter.
s
I suppose I will also need a filter to get only public or private subnets, right?
Maybe something like:`{ name: 'type', value: ['public'] }` ?
w
For the getSubnets function, you are limited to the filters supported by AWS: https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeSubnets.html
👍 1
The other option is to provide the subnet IDs as otuputs from stack A.
And skip the getSubnets() call
s
Yeah, I also did that, but it is not working:
Copy code
module.exports = {
  publicSubnetIds: pulumi.output(vpc.publicSubnetIds)
}
and inside project B i have:
Copy code
const publicSubnetIds = mainStack.getOutput('publicSubnetIds');
const dbSubnetGroup = new aws.rds.SubnetGroup('db-subnet-group', {
  subnetIds: publicSubnetIds
});
I don't know what I'm doing wrong
w
I think the fundamental issue is that the
publicSubnetIds
stack output is read in as an object and so needs to be processed a bit before being used in subnetgroup declaration. In stackB if you do something like
Copy code
module.exports = {
  publicSubnetIdsFromA: pulumi.output(mainStack.getOutput("publicSubnetIds"))
}
you’ll see the subnet IDs made it over to stack b. But to use them as in the subnetgroup declaration requires some type casting or something (that I haven’t figured out yet).
Actually, this works for me:
Copy code
const stackA = new pulumi.StackReference("MitchGerdisch/quick-test/dev")
const pulumiSubnetIdsFromA = pulumi.output(stackA.getOutput("pulumiSubnetIds"))
const dbSubnetGroup = new aws.rds.SubnetGroup('db-subnet-group', {
  subnetIds: pulumiSubnetIdsFromA
});
Actually, it works as well without the
pulumi.output()
bit:
Copy code
const stackA = new pulumi.StackReference("MitchGerdisch/quick-test/dev")
const pulumiSubnetIdsFromA = stackA.getOutput("pulumiSubnetIds")
const dbSubnetGroup = new aws.rds.SubnetGroup('db-subnet-group', {
  subnetIds: pulumiSubnetIdsFromA
});
s
🎉 Yeah, it actually works now, I am so dumb, I specified incorrect stack name inside stackReference 🤦‍♂️ @witty-candle-66007 Thank you soo much for your help! 🙌
w
🙂 Glad you got it working.
🙌 1