@@ -4,7 +4,7 @@ import elbv2 = require('@aws-cdk/aws-elasticloadbalancingv2');
4
4
import { Stack } from '@aws-cdk/core' ;
5
5
import targets = require( '../lib' ) ;
6
6
7
- test ( 'Can create target groups with lambda targets ' , ( ) => {
7
+ test ( 'Can create target groups with instance id target ' , ( ) => {
8
8
// GIVEN
9
9
const stack = new Stack ( ) ;
10
10
const vpc = new ec2 . Vpc ( stack , 'Stack' ) ;
@@ -26,4 +26,34 @@ test('Can create target groups with lambda targets', () => {
26
26
] ,
27
27
TargetType : "instance" ,
28
28
} ) ) ;
29
+ } ) ;
30
+
31
+ test ( 'Can create target groups with instance target' , ( ) => {
32
+ // GIVEN
33
+ const stack = new Stack ( ) ;
34
+ const vpc = new ec2 . Vpc ( stack , 'Stack' ) ;
35
+ const lb = new elbv2 . ApplicationLoadBalancer ( stack , 'LB' , { vpc } ) ;
36
+ const listener = lb . addListener ( 'Listener' , { port : 80 } ) ;
37
+
38
+ const instance = new ec2 . Instance ( stack , 'Instance' , {
39
+ vpc,
40
+ machineImage : new ec2 . AmazonLinuxImage ( ) ,
41
+ instanceType : ec2 . InstanceType . of ( ec2 . InstanceClass . T3 , ec2 . InstanceSize . LARGE ) ,
42
+ } ) ;
43
+
44
+ // WHEN
45
+ listener . addTargets ( 'Targets' , {
46
+ targets : [ new targets . InstanceTarget ( instance ) ] ,
47
+ port : 80 ,
48
+ } ) ;
49
+
50
+ // THEN
51
+ expect ( stack ) . to ( haveResource ( 'AWS::ElasticLoadBalancingV2::TargetGroup' , {
52
+ Port : 80 ,
53
+ Protocol : "HTTP" ,
54
+ Targets : [
55
+ { Id : { Ref : 'InstanceC1063A87' } }
56
+ ] ,
57
+ TargetType : "instance" ,
58
+ } ) ) ;
29
59
} ) ;
0 commit comments