11import  *  as  aws  from  "@pulumi/aws" ; 
22
3- import  {  isPreviewEnvironment  }  from  "../helpers/isPreviewEnvironment" ; 
4- 
53// Create a new VPC 
64export  const  apiVPC  =  new  aws . ec2 . Vpc ( "api-vpc" ,  { 
75  cidrBlock : "10.0.0.0/16" , 
@@ -17,11 +15,15 @@ const internetGateway = new aws.ec2.InternetGateway("api-igw", {
1715} ) ; 
1816
1917// Create Elastic IPs 
20- export  const  apiEip1  =  new  aws . ec2 . Eip ( "api-nat-eip-1" ,  { 
18+ const  apiEip1  =  new  aws . ec2 . Eip ( "api-nat-eip-1" ,  { 
19+   domain : "vpc" , 
20+ } ) ; 
21+ 
22+ const  apiEip2  =  new  aws . ec2 . Eip ( "api-nat-eip-2" ,  { 
2123  domain : "vpc" , 
2224} ) ; 
2325
24- export   const  apiEip2  =  new  aws . ec2 . Eip ( "api-nat-eip-2 " ,  { 
26+ const  apiEip3  =  new  aws . ec2 . Eip ( "api-nat-eip-3 " ,  { 
2527  domain : "vpc" , 
2628} ) ; 
2729
@@ -42,6 +44,14 @@ export const apiPublicSubnet2 = new aws.ec2.Subnet("api-public-subnet-2", {
4244  tags : {  Name : "api-public-subnet-2"  } , 
4345} ) ; 
4446
47+ export  const  apiPublicSubnet3  =  new  aws . ec2 . Subnet ( "api-public-subnet-3" ,  { 
48+   vpcId : apiVPC . id , 
49+   cidrBlock : "10.0.5.0/24" , 
50+   availabilityZone : "us-west-2c" , 
51+   mapPublicIpOnLaunch : true , 
52+   tags : {  Name : "api-public-subnet-3"  } , 
53+ } ) ; 
54+ 
4555// Create a NAT Gateway in each public subnet 
4656const  natGateway1  =  new  aws . ec2 . NatGateway ( "api-nat-gateway-1" ,  { 
4757  allocationId : apiEip1 . id , 
@@ -55,6 +65,12 @@ const natGateway2 = new aws.ec2.NatGateway("api-nat-gateway-2", {
5565  tags : {  Name : "api-nat-gateway-2"  } , 
5666} ) ; 
5767
68+ const  natGateway3  =  new  aws . ec2 . NatGateway ( "api-nat-gateway-3" ,  { 
69+   allocationId : apiEip3 . id , 
70+   subnetId : apiPublicSubnet3 . id , 
71+   tags : {  Name : "api-nat-gateway-3"  } , 
72+ } ) ; 
73+ 
5874// Create private subnets 
5975export  const  apiPrivateSubnet1  =  new  aws . ec2 . Subnet ( "api-private-subnet-1" ,  { 
6076  vpcId : apiVPC . id , 
@@ -70,6 +86,13 @@ export const apiPrivateSubnet2 = new aws.ec2.Subnet("api-private-subnet-2", {
7086  tags : {  Name : "api-private-subnet-2"  } , 
7187} ) ; 
7288
89+ export  const  apiPrivateSubnet3  =  new  aws . ec2 . Subnet ( "api-private-subnet-3" ,  { 
90+   vpcId : apiVPC . id , 
91+   cidrBlock : "10.0.6.0/24" , 
92+   availabilityZone : "us-west-2c" , 
93+   tags : {  Name : "api-private-subnet-3"  } , 
94+ } ) ; 
95+ 
7396// Create route tables 
7497const  publicRouteTable  =  new  aws . ec2 . RouteTable ( "api-public-route-table" ,  { 
7598  vpcId : apiVPC . id , 
@@ -104,6 +127,17 @@ const privateRouteTable2 = new aws.ec2.RouteTable("api-private-route-table-2", {
104127  tags : {  Name : "api-private-route-table-2"  } , 
105128} ) ; 
106129
130+ const  privateRouteTable3  =  new  aws . ec2 . RouteTable ( "api-private-route-table-3" ,  { 
131+   vpcId : apiVPC . id , 
132+   routes : [ 
133+     { 
134+       cidrBlock : "0.0.0.0/0" , 
135+       natGatewayId : natGateway3 . id , 
136+     } , 
137+   ] , 
138+   tags : {  Name : "api-private-route-table-3"  } , 
139+ } ) ; 
140+ 
107141// Associate subnets with route tables 
108142new  aws . ec2 . RouteTableAssociation ( "api-public-route-table-association-1" ,  { 
109143  subnetId : apiPublicSubnet1 . id , 
@@ -115,6 +149,11 @@ new aws.ec2.RouteTableAssociation("api-public-route-table-association-2", {
115149  routeTableId : publicRouteTable . id , 
116150} ) ; 
117151
152+ new  aws . ec2 . RouteTableAssociation ( "api-public-route-table-association-3" ,  { 
153+   subnetId : apiPublicSubnet3 . id , 
154+   routeTableId : publicRouteTable . id , 
155+ } ) ; 
156+ 
118157new  aws . ec2 . RouteTableAssociation ( "api-private-route-table-association-1" ,  { 
119158  subnetId : apiPrivateSubnet1 . id , 
120159  routeTableId : privateRouteTable1 . id , 
@@ -125,6 +164,11 @@ new aws.ec2.RouteTableAssociation("api-private-route-table-association-2", {
125164  routeTableId : privateRouteTable2 . id , 
126165} ) ; 
127166
167+ new  aws . ec2 . RouteTableAssociation ( "api-private-route-table-association-3" ,  { 
168+   subnetId : apiPrivateSubnet3 . id , 
169+   routeTableId : privateRouteTable3 . id , 
170+ } ) ; 
171+ 
128172// Create a Security Group for the Api ALB 
129173export  const  apiAlbSecurityGroup  =  new  aws . ec2 . SecurityGroup ( 
130174  "api-alb-security-group" , 
@@ -170,13 +214,3 @@ export const apiEc2SecurityGroup = new aws.ec2.SecurityGroup("api-sg-1", {
170214  ] , 
171215  tags : {  Name : "api-ec2-security-group"  } , 
172216} ) ; 
173- 
174- if  ( isPreviewEnvironment ) 
175-   new  aws . ec2 . SecurityGroupRule ( `api-ssh-ingress-rule` ,  { 
176-     type : "ingress" , 
177-     fromPort : 22 , 
178-     toPort : 22 , 
179-     protocol : "tcp" , 
180-     cidrBlocks : [ "0.0.0.0/0" ] , 
181-     securityGroupId : apiEc2SecurityGroup . id , 
182-   } ) ; 
0 commit comments