From 77027857f388dd3f06e54de4c86fd2801578e064 Mon Sep 17 00:00:00 2001 From: Nick Lynch Date: Mon, 24 Aug 2020 13:30:53 +0100 Subject: [PATCH] fix(elasticloadbalancingv2): imported listener ignores conditions attribute New conditions attribute usage was fixed in #8385 for owned listeners, but missed imported listeners. fixes #9262 fixes #9320 fixes #9643 --- .../lib/alb/application-listener.ts | 1 + .../test/alb/test.listener.ts | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-listener.ts b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-listener.ts index 7897f5582eb0a..65d6465cb9efe 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-listener.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-listener.ts @@ -571,6 +571,7 @@ class ImportedApplicationListener extends Resource implements IApplicationListen // New rule new ApplicationListenerRule(this, id, { listener: this, + conditions: props.conditions, hostHeader: props.hostHeader, pathPattern: props.pathPattern, pathPatterns: props.pathPatterns, 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 ed851080fa5b0..aa6345eac07cc 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/test/alb/test.listener.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/test/alb/test.listener.ts @@ -464,6 +464,38 @@ export = { test.done(); }, + 'Can call addTargetGroups on imported listener with conditions prop'(test: Test) { + // GIVEN + const stack = new cdk.Stack(); + const vpc = new ec2.Vpc(stack, 'VPC'); + const listener = elbv2.ApplicationListener.fromApplicationListenerAttributes(stack, 'Listener', { + listenerArn: 'ieks', + securityGroupId: 'sg-12345', + }); + const group = new elbv2.ApplicationTargetGroup(stack, 'TargetGroup', { vpc, port: 80 }); + + // WHEN + listener.addTargetGroups('Gruuup', { + priority: 30, + conditions: [elbv2.ListenerCondition.hostHeaders(['example.com'])], + targetGroups: [group], + }); + + // THEN + expect(stack).to(haveResource('AWS::ElasticLoadBalancingV2::ListenerRule', { + ListenerArn: 'ieks', + Priority: 30, + Actions: [ + { + TargetGroupArn: { Ref: 'TargetGroup3D7CD9B8' }, + Type: 'forward', + }, + ], + })); + + test.done(); + }, + 'Can depend on eventual listener via TargetGroup'(test: Test) { // GIVEN const stack = new cdk.Stack();