@@ -14,8 +14,50 @@ export class Testbed extends cdk.Stack {
14
14
constructor ( scope : cdk . Construct , id : string , props : TestbedProps ) {
15
15
super ( scope , id )
16
16
17
- const vpc = new ec2 . Vpc ( this , 'vpc' , { } )
17
+ const vpc = new ec2 . Vpc ( this , id , {
18
+ cidr : '10.0.0.0/16' ,
19
+ maxAzs : 99 ,
20
+ subnetConfiguration : [
21
+ {
22
+ name : 'pub-subnet-1' ,
23
+ subnetType : ec2 . SubnetType . PUBLIC ,
24
+ cidrMask : 28 ,
25
+ } ,
26
+ {
27
+ name : 'priv-subnet-1' ,
28
+ subnetType : ec2 . SubnetType . PRIVATE_WITH_NAT ,
29
+ cidrMask : 28 ,
30
+ } ,
31
+ ] ,
32
+ } ) ;
33
+ //ToDo: revisit once this is resolved - https://github.com/aws/aws-cdk/issues/5927
34
+ // index<=8 will give us 9 /16 cidrs additionally to make a mega VPC.
35
+ for ( let index = 0 ; index <= 8 ; index ++ ) {
36
+ let additionalCidr = new ec2 . CfnVPCCidrBlock ( this , `${ id } -cidr-${ index } ` , {
37
+ vpcId : vpc . vpcId ,
38
+ cidrBlock : `10.${ index + 1 } .0.0/16`
39
+ } ) ;
40
+ let privateSubnet = new ec2 . PrivateSubnet ( this , `${ id } -private-subnet-${ index } ` , {
41
+ availabilityZone : cdk . Stack . of ( this ) . availabilityZones [ index % cdk . Stack . of ( this ) . availabilityZones . length ] ,
42
+ vpcId : vpc . vpcId ,
43
+ cidrBlock : `10.${ index + 1 } .0.0/16`
44
+ } )
45
+ privateSubnet . node . addDependency ( additionalCidr ) ;
18
46
47
+ ec2 . NatProvider . gateway ( ) . configureNat ( {
48
+ natSubnets : [
49
+ new ec2 . PublicSubnet ( this , `${ id } -nat-subnet-${ index } ` , {
50
+ availabilityZone : cdk . Stack . of ( this ) . availabilityZones [ index % cdk . Stack . of ( this ) . availabilityZones . length ] ,
51
+ vpcId : vpc . vpcId ,
52
+ cidrBlock : `10.0.64.${ index * 16 } /28`
53
+ } )
54
+ ] ,
55
+ privateSubnets : [
56
+ privateSubnet
57
+ ] ,
58
+ vpc : vpc
59
+ } )
60
+ }
19
61
const cluster = new eks . Cluster ( this , 'cluster' , {
20
62
clusterName : id ,
21
63
vpc : vpc ,
@@ -33,7 +75,7 @@ export class Testbed extends cdk.Stack {
33
75
cluster . addNodegroupCapacity ( 'node-group' , {
34
76
nodegroupName : 'default' ,
35
77
subnets : vpc . selectSubnets ( {
36
- subnetType : ec2 . SubnetType . PRIVATE
78
+ subnetType : ec2 . SubnetType . PRIVATE_WITH_NAT
37
79
} ) ,
38
80
nodeRole : new iam . Role ( this , 'node-role' , {
39
81
assumedBy : new iam . ServicePrincipal ( 'ec2.amazonaws.com' ) ,
0 commit comments