@@ -434,6 +434,82 @@ describe('vpc', () => {
434
434
435
435
} ) ;
436
436
437
+ test ( 'with public subnets MapPublicIpOnLaunch is true if parameter mapPublicIpOnLaunch is true' , ( ) => {
438
+ const stack = getTestStack ( ) ;
439
+ new Vpc ( stack , 'VPC' , {
440
+ maxAzs : 1 ,
441
+ subnetConfiguration : [
442
+ {
443
+ cidrMask : 24 ,
444
+ name : 'ingress' ,
445
+ subnetType : SubnetType . PUBLIC ,
446
+ mapPublicIpOnLaunch : true ,
447
+ } ,
448
+ ] ,
449
+ } ) ;
450
+ expect ( stack ) . toCountResources ( 'AWS::EC2::Subnet' , 1 ) ;
451
+ expect ( stack ) . not . toHaveResource ( 'AWS::EC2::NatGateway' ) ;
452
+ expect ( stack ) . toHaveResource ( 'AWS::EC2::Subnet' , {
453
+ MapPublicIpOnLaunch : true ,
454
+ } ) ;
455
+ } ) ;
456
+ test ( 'with public subnets MapPublicIpOnLaunch is false if parameter mapPublicIpOnLaunch is false' , ( ) => {
457
+ const stack = getTestStack ( ) ;
458
+ new Vpc ( stack , 'VPC' , {
459
+ maxAzs : 1 ,
460
+ subnetConfiguration : [
461
+ {
462
+ cidrMask : 24 ,
463
+ name : 'ingress' ,
464
+ subnetType : SubnetType . PUBLIC ,
465
+ mapPublicIpOnLaunch : false ,
466
+ } ,
467
+ ] ,
468
+ } ) ;
469
+ expect ( stack ) . toCountResources ( 'AWS::EC2::Subnet' , 1 ) ;
470
+ expect ( stack ) . not . toHaveResource ( 'AWS::EC2::NatGateway' ) ;
471
+ expect ( stack ) . toHaveResource ( 'AWS::EC2::Subnet' , {
472
+ MapPublicIpOnLaunch : false ,
473
+ } ) ;
474
+ } ) ;
475
+ test ( 'with private subnets throw exception if parameter mapPublicIpOnLaunch is defined' , ( ) => {
476
+ const stack = getTestStack ( ) ;
477
+ expect ( ( ) => {
478
+ new Vpc ( stack , 'VPC' , {
479
+ maxAzs : 1 ,
480
+ subnetConfiguration : [
481
+ {
482
+ name : 'public' ,
483
+ subnetType : SubnetType . PUBLIC ,
484
+ } ,
485
+ {
486
+ name : 'private' ,
487
+ subnetType : SubnetType . PRIVATE_WITH_NAT ,
488
+ mapPublicIpOnLaunch : true ,
489
+ } ,
490
+ ] ,
491
+ } ) ;
492
+ } ) . toThrow ( / s u b n e t c a n n o t i n c l u d e m a p P u b l i c I p O n L a u n c h p a r a m e t e r / ) ;
493
+ } ) ;
494
+ test ( 'with isolated subnets throw exception if parameter mapPublicIpOnLaunch is defined' , ( ) => {
495
+ const stack = getTestStack ( ) ;
496
+ expect ( ( ) => {
497
+ new Vpc ( stack , 'VPC' , {
498
+ maxAzs : 1 ,
499
+ subnetConfiguration : [
500
+ {
501
+ name : 'public' ,
502
+ subnetType : SubnetType . PUBLIC ,
503
+ } ,
504
+ {
505
+ name : 'private' ,
506
+ subnetType : SubnetType . PRIVATE_ISOLATED ,
507
+ mapPublicIpOnLaunch : true ,
508
+ } ,
509
+ ] ,
510
+ } ) ;
511
+ } ) . toThrow ( / s u b n e t c a n n o t i n c l u d e m a p P u b l i c I p O n L a u n c h p a r a m e t e r / ) ;
512
+ } ) ;
437
513
test ( 'maxAZs defaults to 3 if unset' , ( ) => {
438
514
const stack = getTestStack ( ) ;
439
515
new Vpc ( stack , 'VPC' ) ;
@@ -1817,4 +1893,4 @@ function hasTags(expectedTags: Array<{Key: string, Value: string}>): (props: any
1817
1893
throw e ;
1818
1894
}
1819
1895
} ;
1820
- }
1896
+ }
0 commit comments