@@ -21,8 +21,42 @@ test('looks up the requested (symmetric) VPC', async () => {
21
21
{ SubnetId : 'sub-789012' , AvailabilityZone : 'bermuda-triangle-1337' , MapPublicIpOnLaunch : false , CidrBlock : '1.1.2.1/24' } ,
22
22
] ,
23
23
routeTables : [
24
- { Associations : [ { SubnetId : 'sub-123456' } ] , RouteTableId : 'rtb-123456' } ,
25
- { Associations : [ { SubnetId : 'sub-789012' } ] , RouteTableId : 'rtb-789012' } ,
24
+ {
25
+ Associations : [ { SubnetId : 'sub-123456' } ] ,
26
+ RouteTableId : 'rtb-123456' ,
27
+ Routes : [
28
+ {
29
+ DestinationCidrBlock : '1.1.1.1/24' ,
30
+ GatewayId : 'local' ,
31
+ Origin : 'CreateRouteTable' ,
32
+ State : 'active' ,
33
+ } ,
34
+ {
35
+ DestinationCidrBlock : '0.0.0.0/0' ,
36
+ GatewayId : 'igw-xxxxxx' ,
37
+ Origin : 'CreateRoute' ,
38
+ State : 'active' ,
39
+ } ,
40
+ ] ,
41
+ } ,
42
+ {
43
+ Associations : [ { SubnetId : 'sub-789012' } ] ,
44
+ RouteTableId : 'rtb-789012' ,
45
+ Routes : [
46
+ {
47
+ DestinationCidrBlock : '1.1.2.1/24' ,
48
+ GatewayId : 'local' ,
49
+ Origin : 'CreateRouteTable' ,
50
+ State : 'active' ,
51
+ } ,
52
+ {
53
+ DestinationCidrBlock : '0.0.0.0/0' ,
54
+ NatGatewayId : 'nat-xxxxxx' ,
55
+ Origin : 'CreateRoute' ,
56
+ State : 'active' ,
57
+ } ,
58
+ ] ,
59
+ } ,
26
60
] ,
27
61
vpnGateways : [ { VpnGatewayId : 'gw-abcdef' } ] ,
28
62
@@ -115,8 +149,42 @@ test('uses the VPC main route table when a subnet has no specific association',
115
149
{ SubnetId : 'sub-789012' , AvailabilityZone : 'bermuda-triangle-1337' , MapPublicIpOnLaunch : false , CidrBlock : '1.1.2.1/24' } ,
116
150
] ,
117
151
routeTables : [
118
- { Associations : [ { SubnetId : 'sub-123456' } ] , RouteTableId : 'rtb-123456' } ,
119
- { Associations : [ { Main : true } ] , RouteTableId : 'rtb-789012' } ,
152
+ {
153
+ Associations : [ { SubnetId : 'sub-123456' } ] ,
154
+ RouteTableId : 'rtb-123456' ,
155
+ Routes : [
156
+ {
157
+ DestinationCidrBlock : '1.1.1.1/24' ,
158
+ GatewayId : 'local' ,
159
+ Origin : 'CreateRouteTable' ,
160
+ State : 'active' ,
161
+ } ,
162
+ {
163
+ DestinationCidrBlock : '0.0.0.0/0' ,
164
+ GatewayId : 'igw-xxxxxx' ,
165
+ Origin : 'CreateRoute' ,
166
+ State : 'active' ,
167
+ } ,
168
+ ] ,
169
+ } ,
170
+ {
171
+ Associations : [ { Main : true } ] ,
172
+ RouteTableId : 'rtb-789012' ,
173
+ Routes : [
174
+ {
175
+ DestinationCidrBlock : '1.1.2.1/24' ,
176
+ GatewayId : 'local' ,
177
+ Origin : 'CreateRouteTable' ,
178
+ State : 'active' ,
179
+ } ,
180
+ {
181
+ DestinationCidrBlock : '0.0.0.0/0' ,
182
+ NatGatewayId : 'nat-xxxxxx' ,
183
+ Origin : 'CreateRoute' ,
184
+ State : 'active' ,
185
+ } ,
186
+ ] ,
187
+ } ,
120
188
] ,
121
189
vpnGateways : [ { VpnGatewayId : 'gw-abcdef' } ] ,
122
190
} ) ;
@@ -189,7 +257,7 @@ test('Recognize public subnet by route table', async () => {
189
257
VpcPeeringConnectionId : 'pcx-xxxxxx' ,
190
258
} ,
191
259
{
192
- DestinationCidrBlock : '10.0 .1.0 /24' ,
260
+ DestinationCidrBlock : '1.1 .1.1 /24' ,
193
261
GatewayId : 'local' ,
194
262
Origin : 'CreateRouteTable' ,
195
263
State : 'active' ,
@@ -245,6 +313,142 @@ test('Recognize public subnet by route table', async () => {
245
313
} ) ;
246
314
} ) ;
247
315
316
+ test ( 'Recognize isolated subnet by route table' , async ( ) => {
317
+ // GIVEN
318
+ mockVpcLookup ( {
319
+ subnets : [
320
+ { SubnetId : 'sub-123456' , AvailabilityZone : 'bermuda-triangle-1337' , MapPublicIpOnLaunch : false } ,
321
+ ] ,
322
+ routeTables : [
323
+ {
324
+ Associations : [ { SubnetId : 'sub-123456' } ] ,
325
+ RouteTableId : 'rtb-123456' ,
326
+ Routes : [
327
+ {
328
+ DestinationCidrBlock : '1.1.2.1/24' ,
329
+ GatewayId : 'local' ,
330
+ Origin : 'CreateRouteTable' ,
331
+ State : 'active' ,
332
+ } ,
333
+ ] ,
334
+ } ,
335
+ ] ,
336
+ } ) ;
337
+
338
+ // WHEN
339
+ const result = await new VpcNetworkContextProviderPlugin ( mockSDK ) . getValue ( {
340
+ account : '1234' ,
341
+ region : 'us-east-1' ,
342
+ filter : { foo : 'bar' } ,
343
+ returnAsymmetricSubnets : true ,
344
+ } ) ;
345
+
346
+ // THEN
347
+ expect ( result ) . toEqual ( {
348
+ availabilityZones : [ ] ,
349
+ vpcCidrBlock : '1.1.1.1/16' ,
350
+ isolatedSubnetIds : undefined ,
351
+ isolatedSubnetNames : undefined ,
352
+ isolatedSubnetRouteTableIds : undefined ,
353
+ privateSubnetIds : undefined ,
354
+ privateSubnetNames : undefined ,
355
+ privateSubnetRouteTableIds : undefined ,
356
+ publicSubnetIds : undefined ,
357
+ publicSubnetNames : undefined ,
358
+ publicSubnetRouteTableIds : undefined ,
359
+ subnetGroups : [
360
+ {
361
+ name : 'Isolated' ,
362
+ type : 'Isolated' ,
363
+ subnets : [
364
+ {
365
+ subnetId : 'sub-123456' ,
366
+ availabilityZone : 'bermuda-triangle-1337' ,
367
+ routeTableId : 'rtb-123456' ,
368
+ cidr : undefined ,
369
+ } ,
370
+ ] ,
371
+ } ,
372
+ ] ,
373
+ vpcId : 'vpc-1234567' ,
374
+ vpnGatewayId : undefined ,
375
+ } ) ;
376
+ } ) ;
377
+
378
+ test ( 'Recognize private subnet by route table' , async ( ) => {
379
+ // GIVEN
380
+ mockVpcLookup ( {
381
+ subnets : [
382
+ { SubnetId : 'sub-123456' , AvailabilityZone : 'bermuda-triangle-1337' , MapPublicIpOnLaunch : false } ,
383
+ ] ,
384
+ routeTables : [
385
+ {
386
+ Associations : [ { SubnetId : 'sub-123456' } ] ,
387
+ RouteTableId : 'rtb-123456' ,
388
+ Routes : [
389
+ {
390
+ DestinationCidrBlock : '10.0.2.0/26' ,
391
+ Origin : 'CreateRoute' ,
392
+ State : 'active' ,
393
+ VpcPeeringConnectionId : 'pcx-xxxxxx' ,
394
+ } ,
395
+ {
396
+ DestinationCidrBlock : '1.1.2.1/24' ,
397
+ GatewayId : 'local' ,
398
+ Origin : 'CreateRouteTable' ,
399
+ State : 'active' ,
400
+ } ,
401
+ {
402
+ DestinationCidrBlock : '0.0.0.0/0' ,
403
+ NatGatewayId : 'nat-xxxxxx' ,
404
+ Origin : 'CreateRoute' ,
405
+ State : 'active' ,
406
+ } ,
407
+ ] ,
408
+ } ,
409
+ ] ,
410
+ } ) ;
411
+
412
+ // WHEN
413
+ const result = await new VpcNetworkContextProviderPlugin ( mockSDK ) . getValue ( {
414
+ account : '1234' ,
415
+ region : 'us-east-1' ,
416
+ filter : { foo : 'bar' } ,
417
+ returnAsymmetricSubnets : true ,
418
+ } ) ;
419
+
420
+ // THEN
421
+ expect ( result ) . toEqual ( {
422
+ availabilityZones : [ ] ,
423
+ vpcCidrBlock : '1.1.1.1/16' ,
424
+ isolatedSubnetIds : undefined ,
425
+ isolatedSubnetNames : undefined ,
426
+ isolatedSubnetRouteTableIds : undefined ,
427
+ privateSubnetIds : undefined ,
428
+ privateSubnetNames : undefined ,
429
+ privateSubnetRouteTableIds : undefined ,
430
+ publicSubnetIds : undefined ,
431
+ publicSubnetNames : undefined ,
432
+ publicSubnetRouteTableIds : undefined ,
433
+ subnetGroups : [
434
+ {
435
+ name : 'Private' ,
436
+ type : 'Private' ,
437
+ subnets : [
438
+ {
439
+ subnetId : 'sub-123456' ,
440
+ availabilityZone : 'bermuda-triangle-1337' ,
441
+ routeTableId : 'rtb-123456' ,
442
+ cidr : undefined ,
443
+ } ,
444
+ ] ,
445
+ } ,
446
+ ] ,
447
+ vpcId : 'vpc-1234567' ,
448
+ vpnGatewayId : undefined ,
449
+ } ) ;
450
+ } ) ;
451
+
248
452
test ( 'works for asymmetric subnets (not spanning the same Availability Zones)' , async ( ) => {
249
453
// GIVEN
250
454
mockVpcLookup ( {
@@ -255,7 +459,30 @@ test('works for asymmetric subnets (not spanning the same Availability Zones)',
255
459
{ SubnetId : 'pub-sub-in-1a' , AvailabilityZone : 'us-west-1a' , MapPublicIpOnLaunch : true , CidrBlock : '1.1.4.1/24' } ,
256
460
] ,
257
461
routeTables : [
258
- { Associations : [ { Main : true } ] , RouteTableId : 'rtb-123' } ,
462
+ {
463
+ Associations : [ { SubnetId : 'pri-sub-in-1b' } ] ,
464
+ RouteTableId : 'rtb-123456' ,
465
+ Routes : [
466
+ {
467
+ DestinationCidrBlock : '0.0.0.0/0' ,
468
+ NatGatewayId : 'nat-xxxxxx' ,
469
+ Origin : 'CreateRoute' ,
470
+ State : 'active' ,
471
+ } ,
472
+ ] ,
473
+ } ,
474
+ {
475
+ Associations : [ { Main : true } ] ,
476
+ RouteTableId : 'rtb-789012' ,
477
+ Routes : [
478
+ {
479
+ DestinationCidrBlock : '0.0.0.0/0' ,
480
+ GatewayId : 'igw-xxxxxx' ,
481
+ Origin : 'CreateRoute' ,
482
+ State : 'active' ,
483
+ } ,
484
+ ] ,
485
+ } ,
259
486
] ,
260
487
} ) ;
261
488
@@ -288,7 +515,7 @@ test('works for asymmetric subnets (not spanning the same Availability Zones)',
288
515
{
289
516
subnetId : 'pri-sub-in-1b' ,
290
517
availabilityZone : 'us-west-1b' ,
291
- routeTableId : 'rtb-123 ' ,
518
+ routeTableId : 'rtb-123456 ' ,
292
519
cidr : '1.1.1.1/24' ,
293
520
} ,
294
521
] ,
@@ -300,19 +527,19 @@ test('works for asymmetric subnets (not spanning the same Availability Zones)',
300
527
{
301
528
subnetId : 'pub-sub-in-1a' ,
302
529
availabilityZone : 'us-west-1a' ,
303
- routeTableId : 'rtb-123 ' ,
530
+ routeTableId : 'rtb-789012 ' ,
304
531
cidr : '1.1.4.1/24' ,
305
532
} ,
306
533
{
307
534
subnetId : 'pub-sub-in-1b' ,
308
535
availabilityZone : 'us-west-1b' ,
309
- routeTableId : 'rtb-123 ' ,
536
+ routeTableId : 'rtb-789012 ' ,
310
537
cidr : '1.1.3.1/24' ,
311
538
} ,
312
539
{
313
540
subnetId : 'pub-sub-in-1c' ,
314
541
availabilityZone : 'us-west-1c' ,
315
- routeTableId : 'rtb-123 ' ,
542
+ routeTableId : 'rtb-789012 ' ,
316
543
cidr : '1.1.2.1/24' ,
317
544
} ,
318
545
] ,
@@ -361,7 +588,30 @@ test('allows specifying the subnet group name tag', async () => {
361
588
} ,
362
589
] ,
363
590
routeTables : [
364
- { Associations : [ { Main : true } ] , RouteTableId : 'rtb-123' } ,
591
+ {
592
+ Associations : [ { SubnetId : 'pri-sub-in-1b' } ] ,
593
+ RouteTableId : 'rtb-123456' ,
594
+ Routes : [
595
+ {
596
+ DestinationCidrBlock : '0.0.0.0/0' ,
597
+ NatGatewayId : 'nat-xxxxxx' ,
598
+ Origin : 'CreateRoute' ,
599
+ State : 'active' ,
600
+ } ,
601
+ ] ,
602
+ } ,
603
+ {
604
+ Associations : [ { Main : true } ] ,
605
+ RouteTableId : 'rtb-789012' ,
606
+ Routes : [
607
+ {
608
+ DestinationCidrBlock : '0.0.0.0/0' ,
609
+ GatewayId : 'igw-xxxxxx' ,
610
+ Origin : 'CreateRoute' ,
611
+ State : 'active' ,
612
+ } ,
613
+ ] ,
614
+ } ,
365
615
] ,
366
616
} ) ;
367
617
@@ -393,7 +643,7 @@ test('allows specifying the subnet group name tag', async () => {
393
643
{
394
644
subnetId : 'pri-sub-in-1b' ,
395
645
availabilityZone : 'us-west-1b' ,
396
- routeTableId : 'rtb-123 ' ,
646
+ routeTableId : 'rtb-123456 ' ,
397
647
cidr : undefined ,
398
648
} ,
399
649
] ,
@@ -405,19 +655,19 @@ test('allows specifying the subnet group name tag', async () => {
405
655
{
406
656
subnetId : 'pub-sub-in-1a' ,
407
657
availabilityZone : 'us-west-1a' ,
408
- routeTableId : 'rtb-123 ' ,
658
+ routeTableId : 'rtb-789012 ' ,
409
659
cidr : undefined ,
410
660
} ,
411
661
{
412
662
subnetId : 'pub-sub-in-1b' ,
413
663
availabilityZone : 'us-west-1b' ,
414
- routeTableId : 'rtb-123 ' ,
664
+ routeTableId : 'rtb-789012 ' ,
415
665
cidr : undefined ,
416
666
} ,
417
667
{
418
668
subnetId : 'pub-sub-in-1c' ,
419
669
availabilityZone : 'us-west-1c' ,
420
- routeTableId : 'rtb-123 ' ,
670
+ routeTableId : 'rtb-789012 ' ,
421
671
cidr : undefined ,
422
672
} ,
423
673
] ,
0 commit comments