@@ -5,8 +5,19 @@ import { Asset } from '@aws-cdk/aws-s3-assets';
5
5
import { StringParameter } from '@aws-cdk/aws-ssm' ;
6
6
import { Stack } from '@aws-cdk/core' ;
7
7
import {
8
- AmazonLinuxImage , BlockDeviceVolume , CloudFormationInit ,
9
- EbsDeviceVolumeType , InitCommand , Instance , InstanceArchitecture , InstanceClass , InstanceSize , InstanceType , LaunchTemplate , UserData , Vpc ,
8
+ AmazonLinuxImage ,
9
+ BlockDeviceVolume ,
10
+ CloudFormationInit ,
11
+ EbsDeviceVolumeType ,
12
+ InitCommand ,
13
+ Instance ,
14
+ InstanceArchitecture ,
15
+ InstanceClass ,
16
+ InstanceSize ,
17
+ InstanceType ,
18
+ LaunchTemplate ,
19
+ UserData ,
20
+ Vpc ,
10
21
} from '../lib' ;
11
22
12
23
let stack : Stack ;
@@ -144,7 +155,7 @@ describe('instance', () => {
144
155
145
156
for ( const instanceClass of sampleInstanceClassKeys ) {
146
157
// WHEN
147
- const key = instanceClass . key as keyof ( typeof InstanceClass ) ;
158
+ const key = instanceClass . key as keyof ( typeof InstanceClass ) ;
148
159
const instanceType = InstanceClass [ key ] ;
149
160
150
161
// THEN
@@ -432,6 +443,62 @@ describe('instance', () => {
432
443
} ,
433
444
} ) ;
434
445
} ) ;
446
+
447
+ describe ( 'Detailed Monitoring' , ( ) => {
448
+ test ( 'instance with Detailed Monitoring enabled' , ( ) => {
449
+ // WHEN
450
+ new Instance ( stack , 'Instance' , {
451
+ vpc,
452
+ machineImage : new AmazonLinuxImage ( ) ,
453
+ instanceType : new InstanceType ( 't2.micro' ) ,
454
+ detailedMonitoring : true ,
455
+ } ) ;
456
+
457
+ // Force stack synth so the Instance is applied
458
+ Template . fromStack ( stack ) ;
459
+
460
+ // THEN
461
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::EC2::Instance' , {
462
+ Monitoring : true ,
463
+ } ) ;
464
+ } ) ;
465
+
466
+ test ( 'instance with Detailed Monitoring disabled' , ( ) => {
467
+ // WHEN
468
+ new Instance ( stack , 'Instance' , {
469
+ vpc,
470
+ machineImage : new AmazonLinuxImage ( ) ,
471
+ instanceType : new InstanceType ( 't2.micro' ) ,
472
+ detailedMonitoring : false ,
473
+ } ) ;
474
+
475
+ // Force stack synth so the Instance is applied
476
+ Template . fromStack ( stack ) ;
477
+
478
+ // THEN
479
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::EC2::Instance' , {
480
+ Monitoring : false ,
481
+ } ) ;
482
+ } ) ;
483
+
484
+ test ( 'instance with Detailed Monitoring unset falls back to disabled' , ( ) => {
485
+ // WHEN
486
+ new Instance ( stack , 'Instance' , {
487
+ vpc,
488
+ machineImage : new AmazonLinuxImage ( ) ,
489
+ instanceType : new InstanceType ( 't2.micro' ) ,
490
+ } ) ;
491
+
492
+ // Force stack synth so the Instance is applied
493
+ Template . fromStack ( stack ) ;
494
+
495
+ // THEN
496
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::EC2::Instance' , {
497
+ Monitoring : Match . absent ( ) ,
498
+ } ) ;
499
+ } ) ;
500
+ } ) ;
501
+
435
502
} ) ;
436
503
437
504
test ( 'add CloudFormation Init to instance' , ( ) => {
@@ -519,8 +586,14 @@ test('cause replacement from s3 asset in userdata', () => {
519
586
const hash = 'f88eace39faf39d7' ;
520
587
Template . fromStack ( stack ) . templateMatches ( Match . objectLike ( {
521
588
Resources : Match . objectLike ( {
522
- [ `InstanceOne5B821005${ hash } ` ] : Match . objectLike ( { Type : 'AWS::EC2::Instance' , Properties : Match . anyValue ( ) } ) ,
523
- [ `InstanceTwoDC29A7A7${ hash } ` ] : Match . objectLike ( { Type : 'AWS::EC2::Instance' , Properties : Match . anyValue ( ) } ) ,
589
+ [ `InstanceOne5B821005${ hash } ` ] : Match . objectLike ( {
590
+ Type : 'AWS::EC2::Instance' ,
591
+ Properties : Match . anyValue ( ) ,
592
+ } ) ,
593
+ [ `InstanceTwoDC29A7A7${ hash } ` ] : Match . objectLike ( {
594
+ Type : 'AWS::EC2::Instance' ,
595
+ Properties : Match . anyValue ( ) ,
596
+ } ) ,
524
597
} ) ,
525
598
} ) ) ;
526
599
} ) ;
0 commit comments