I am trying to create cdk typescripts for vpc peering between 2 vpcs in 2 separate accounts. The relevant piece of code as follows. The vpcs are created fine, however I am not able to refer the vpcId and peerVpcId from the vpc1 and vpc2. Can anyone help please. Any working example code would be really helpful. Thanks.
//creation of vpc 1
export class vpc1 extends cdk.Stack {
constructor(scope: cdk.App, id: string, props: EnvProps) {
super(scope, id, props);
const vpc = new ec2.Vpc(this, 'vpc1',{
cidr: props.vpcCidr ,
enableDnsHostnames: true,
enableDnsSupport: true,
maxAzs: 3,
subnetConfiguration: [{
cidrMask: 24,
name: 'Public',
subnetType: ec2.SubnetType.PUBLIC,
},
{
cidrMask: 24,
name: 'Private',
subnetType: ec2.SubnetType.PRIVATE,
}],
natGateways: 1
}); }}
//creation of vpc 2
export class vpc2 extends cdk.Stack {
constructor(scope: cdk.App, id: string, props: EnvProps) {
super(scope, id, props);
const vpc = new ec2.Vpc(this, 'vpc2',{
cidr: props.vpcCidr ,
enableDnsHostnames: true,
enableDnsSupport: true,
maxAzs: 3,
subnetConfiguration: [{
cidrMask: 24,
name: 'Public',
subnetType: ec2.SubnetType.PUBLIC,
},
{
cidrMask: 24,
name: 'Private',
subnetType: ec2.SubnetType.PRIVATE,
}],
natGateways: 1
});
}}
export class vpcPeeringfisHiDev extends cdk.Stack {
constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const vpc_peering = new ec2.CfnVPCPeeringConnection (this, 'vpcPeer',{
vpcId: vpc1.vpc.vpcId, //Error - Property 'vpc' does not exist on type 'typeof vpc1'.ts(2339)
peerVpcId: vpc2.vpc.vpcId //Error - Property 'vpc' does not exist on type 'typeof vpc2'.ts(2339)
}); }}