From 1fcbaaa987fe6fac52bfd5e9b30da9e174f29404 Mon Sep 17 00:00:00 2001 From: Simon-Pierre Gingras <892367+spg@users.noreply.github.com> Date: Fri, 30 Jul 2021 10:26:34 -0400 Subject: [PATCH] fix(elbv2): unresolved listener priority throws error (#15804) Fixes an issue where unresolved Listener `priority` would resolve in Error: `Priority must have value greater than or equal to 1`. This adds support for cases where the Listener `priority` can be supplied through CloudFormation Template Parameters. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- .../lib/alb/application-listener-rule.ts | 2 +- .../test/alb/listener.test.ts | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-listener-rule.ts b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-listener-rule.ts index 7a3bb91cb3457..e71ccbd5c74de 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-listener-rule.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-listener-rule.ts @@ -229,7 +229,7 @@ export class ApplicationListenerRule extends CoreConstruct { throw new Error(`'${providedActions}' specified together, specify only one`); } - if (props.priority <= 0) { + if (!cdk.Token.isUnresolved(props.priority) && props.priority <= 0) { throw new Error('Priority must have value greater than or equal to 1'); } diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/test/alb/listener.test.ts b/packages/@aws-cdk/aws-elasticloadbalancingv2/test/alb/listener.test.ts index 6de716df113e2..fffc6e365bcea 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/test/alb/listener.test.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/test/alb/listener.test.ts @@ -987,6 +987,28 @@ describe('tests', () => { })).toThrowError('Priority must have value greater than or equal to 1'); }); + test('Accepts unresolved priority', () => { + // GIVEN + const stack = new cdk.Stack(); + const vpc = new ec2.Vpc(stack, 'VPC'); + const lb = new elbv2.ApplicationLoadBalancer(stack, 'LoadBalancer', { + vpc, + }); + const listener = lb.addListener('Listener', { + port: 80, + }); + + // THEN + expect(() => new elbv2.ApplicationListenerRule(stack, 'Rule', { + listener, + priority: new cdk.CfnParameter(stack, 'PriorityParam', { type: 'Number' }).valueAsNumber, + pathPattern: '/hello', + fixedResponse: { + statusCode: '500', + }, + })).not.toThrowError('Priority must have value greater than or equal to 1'); + }); + test('Throws when specifying both target groups and redirect response', () => { // GIVEN const stack = new cdk.Stack();