diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-target-group.ts b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-target-group.ts index 7a3aaf83df5fd..81d88262c283b 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-target-group.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-target-group.ts @@ -40,6 +40,17 @@ export interface BaseTargetGroupProps { * @default No health check */ healthCheck?: HealthCheck; + + /** + * The type of targets registered to this TargetGroup, either IP or Instance. + * + * All targets registered into the group must be of this type. If you + * register targets to the TargetGroup in the CDK app, the TargetType is + * determined automatically. + * + * @default Determined automatically + */ + targetType?: TargetType; } /** @@ -179,6 +190,7 @@ export abstract class BaseTargetGroup extends cdk.Construct implements ITargetGr } this.healthCheck = baseProps.healthCheck || {}; + this.targetType = baseProps.targetType; this.resource = new cloudformation.TargetGroupResource(this, 'Resource', { targetGroupName: baseProps.targetGroupName, diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/test/alb/test.listener.ts b/packages/@aws-cdk/aws-elasticloadbalancingv2/test/alb/test.listener.ts index 7f148005cbb2e..2f42dd58206b0 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/test/alb/test.listener.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/test/alb/test.listener.ts @@ -93,6 +93,26 @@ export = { test.done(); }, + 'Can configure targetType on TargetGroups'(test: Test) { + // GIVEN + const stack = new cdk.Stack(); + const vpc = new ec2.VpcNetwork(stack, 'Stack'); + + // WHEN + new elbv2.ApplicationTargetGroup(stack, 'TargetGroup', { + vpc, + port: 80, + targetType: elbv2.TargetType.Ip + }); + + // THEN + expect(stack).to(haveResource('AWS::ElasticLoadBalancingV2::TargetGroup', { + TargetType: 'ip' + })); + + test.done(); + }, + 'Can add target groups with and without conditions'(test: Test) { // GIVEN const stack = new cdk.Stack();