Skip to content

Commit b4293f2

Browse files
authoredNov 15, 2018
fix(aws-elasticloadbalancingv2): 'targetType' on groups (#1174)
It's now possible to configure a 'targetType' on empty TargetGroups.
1 parent c1ea944 commit b4293f2

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed
 

‎packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-target-group.ts

+12
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ export interface BaseTargetGroupProps {
4040
* @default No health check
4141
*/
4242
healthCheck?: HealthCheck;
43+
44+
/**
45+
* The type of targets registered to this TargetGroup, either IP or Instance.
46+
*
47+
* All targets registered into the group must be of this type. If you
48+
* register targets to the TargetGroup in the CDK app, the TargetType is
49+
* determined automatically.
50+
*
51+
* @default Determined automatically
52+
*/
53+
targetType?: TargetType;
4354
}
4455

4556
/**
@@ -179,6 +190,7 @@ export abstract class BaseTargetGroup extends cdk.Construct implements ITargetGr
179190
}
180191

181192
this.healthCheck = baseProps.healthCheck || {};
193+
this.targetType = baseProps.targetType;
182194

183195
this.resource = new cloudformation.TargetGroupResource(this, 'Resource', {
184196
targetGroupName: baseProps.targetGroupName,

‎packages/@aws-cdk/aws-elasticloadbalancingv2/test/alb/test.listener.ts

+20
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,26 @@ export = {
9393
test.done();
9494
},
9595

96+
'Can configure targetType on TargetGroups'(test: Test) {
97+
// GIVEN
98+
const stack = new cdk.Stack();
99+
const vpc = new ec2.VpcNetwork(stack, 'Stack');
100+
101+
// WHEN
102+
new elbv2.ApplicationTargetGroup(stack, 'TargetGroup', {
103+
vpc,
104+
port: 80,
105+
targetType: elbv2.TargetType.Ip
106+
});
107+
108+
// THEN
109+
expect(stack).to(haveResource('AWS::ElasticLoadBalancingV2::TargetGroup', {
110+
TargetType: 'ip'
111+
}));
112+
113+
test.done();
114+
},
115+
96116
'Can add target groups with and without conditions'(test: Test) {
97117
// GIVEN
98118
const stack = new cdk.Stack();

0 commit comments

Comments
 (0)