From 201bc475d3d48caf54df58efcc44f360d83299d0 Mon Sep 17 00:00:00 2001 From: Andrew Hammond <445764+ahammond@users.noreply.github.com> Date: Fri, 5 Apr 2024 13:55:08 -0700 Subject: [PATCH 1/5] feat(elasticloadbalancingv2): removeRuleSuffixFromLogicalId support --- .../lib/alb/application-listener.ts | 29 ++++++++- .../test/alb/listener.test.ts | 65 +++++++++++++++++++ 2 files changed, 92 insertions(+), 2 deletions(-) diff --git a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-listener.ts b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-listener.ts index bbb7d02f34214..d91955300e6b3 100644 --- a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-listener.ts +++ b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-listener.ts @@ -625,8 +625,9 @@ abstract class ExternalApplicationListener extends Resource implements IApplicat checkAddRuleProps(props); if (props.priority !== undefined) { + const ruleId = props.removeRuleSuffixFromLogicalId ? id : id + 'Rule'; // New rule - new ApplicationListenerRule(this, id, { + new ApplicationListenerRule(this, ruleId, { listener: this, priority: props.priority, ...props, @@ -669,10 +670,11 @@ abstract class ExternalApplicationListener extends Resource implements IApplicat checkAddRuleProps(props); if (props.priority !== undefined) { + const ruleId = props.removeRuleSuffixFromLogicalId ? id : id + 'Rule'; // New rule // // TargetGroup.registerListener is called inside ApplicationListenerRule. - new ApplicationListenerRule(this, id + 'Rule', { + new ApplicationListenerRule(this, ruleId, { listener: this, priority: props.priority, ...props, @@ -797,6 +799,16 @@ export interface AddApplicationTargetGroupsProps extends AddRuleProps { * Target groups to forward requests to */ readonly targetGroups: IApplicationTargetGroup[]; + /** + * `ListenerRule`s have a `Rule` suffix on their logicalId by default. + * + * Legacy behavior did not include the `Rule` suffix on the logicalId of the generated `ListenerRule` + * when generated by the `addTargetGroups()` method. + * This exists to allow backwards compatible behavior with `ListenerRule`s deployed by older versions of aws-cdk. + * + * @default - do not remove the logicalId `Rule` suffix + */ + readonly removeRuleSuffixFromLogicalId?: boolean; } /** @@ -807,6 +819,19 @@ export interface AddApplicationActionProps extends AddRuleProps { * Action to perform */ readonly action: ListenerAction; + /** + * `ListenerRule`s have a `Rule` suffix on their logicalId by default. This allows you to remove that suffix. + * + * Legacy behavior of the `addTargetGroups()` convenience method did not include the `Rule` suffix on the logicalId of the generated `ListenerRule`. + * At some point, increasing complexity of requirements can require users to switch from the `addTargetGroups()` method + * to the `addAction()` method. + * When migrating `ListenerRule`s deployed by a legacy version of `addTargetGroups()`, + * you will need to enable this flag to avoid changing the logicalId of your resource. + * Otherwise Cfn will attempt to replace the `ListenerRule` and fail. + * + * @default - use standard logicalId with the `Rule` suffix + */ + readonly removeRuleSuffixFromLogicalId?: boolean; } /** diff --git a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/test/alb/listener.test.ts b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/test/alb/listener.test.ts index 907cf8a20a683..4556026bb432e 100644 --- a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/test/alb/listener.test.ts +++ b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/test/alb/listener.test.ts @@ -1698,6 +1698,71 @@ describe('tests', () => { }).toThrow(/Specify at most one/); }); + describe('Rule suffix for logicalId', () => { + interface TestCase { + readonly removeRuleSuffixFromLogicalId: boolean; + }; + const testCases: TestCase[] = [ + { removeRuleSuffixFromLogicalId: true }, + { removeRuleSuffixFromLogicalId: false }, + ]; + test.each(testCases)('addTargetGroups %s', ({ removeRuleSuffixFromLogicalId }) => { + // GIVEN + const identifierToken = 'SuperMagicToken'; + const app = new cdk.App(); + const stack = new cdk.Stack(app, 'TestStack', { env: {account: '123456789012', region: 'us-east-1'} }); + const vpc = new ec2.Vpc(stack, 'Stack'); + const targetGroup = new elbv2.ApplicationTargetGroup(stack, 'TargetGroup', { vpc, port: 80 }); + const listener = elbv2.ApplicationListener.fromLookup(stack, 'a', { + loadBalancerTags: { + some: 'tag', + }, + }); + + // WHEN + listener.addTargetGroups(identifierToken, { + conditions: [elbv2.ListenerCondition.pathPatterns(['/fake'])], + priority: 42, + targetGroups: [targetGroup], + removeRuleSuffixFromLogicalId, + }); + + // THEN + const expectedLogicalId = removeRuleSuffixFromLogicalId ? identifierToken : identifierToken + 'Rule'; + const applicationListenerRule = listener.node.children.find((v)=> v.hasOwnProperty('conditions')); + expect(applicationListenerRule).toBeDefined(); + expect(applicationListenerRule!.node.id).toBe(expectedLogicalId); + }); + + test.each(testCases)('addAction %s', ({ removeRuleSuffixFromLogicalId }) => { + // GIVEN + const identifierToken = 'SuperMagicToken'; + const app = new cdk.App(); + const stack = new cdk.Stack(app, 'TestStack', { env: {account: '123456789012', region: 'us-east-1'} }); + const vpc = new ec2.Vpc(stack, 'Stack'); + const targetGroup = new elbv2.ApplicationTargetGroup(stack, 'TargetGroup', { vpc, port: 80 }); + const listener = elbv2.ApplicationListener.fromLookup(stack, 'a', { + loadBalancerTags: { + some: 'tag', + }, + }); + + // WHEN + listener.addAction(identifierToken, { + action: elbv2.ListenerAction.weightedForward([{ targetGroup, weight: 1 }]), + conditions: [elbv2.ListenerCondition.pathPatterns(['/fake'])], + priority: 42, + removeRuleSuffixFromLogicalId, + }); + + // THEN + const expectedLogicalId = removeRuleSuffixFromLogicalId ? identifierToken : identifierToken + 'Rule'; + const applicationListenerRule = listener.node.children.find((v)=> v.hasOwnProperty('conditions')); + expect(applicationListenerRule).toBeDefined(); + expect(applicationListenerRule!.node.id).toBe(expectedLogicalId); + }); + }); + describe('lookup', () => { test('Can look up an ApplicationListener', () => { // GIVEN From a29dd228757c256b69d69d72c3cec6e79ab59e19 Mon Sep 17 00:00:00 2001 From: Andrew Hammond <445764+ahammond@users.noreply.github.com> Date: Fri, 5 Apr 2024 14:14:03 -0700 Subject: [PATCH 2/5] lint --- .../aws-elasticloadbalancingv2/test/alb/listener.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/test/alb/listener.test.ts b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/test/alb/listener.test.ts index 4556026bb432e..1602665e63142 100644 --- a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/test/alb/listener.test.ts +++ b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/test/alb/listener.test.ts @@ -1710,7 +1710,7 @@ describe('tests', () => { // GIVEN const identifierToken = 'SuperMagicToken'; const app = new cdk.App(); - const stack = new cdk.Stack(app, 'TestStack', { env: {account: '123456789012', region: 'us-east-1'} }); + const stack = new cdk.Stack(app, 'TestStack', { env: { account: '123456789012', region: 'us-east-1' } }); const vpc = new ec2.Vpc(stack, 'Stack'); const targetGroup = new elbv2.ApplicationTargetGroup(stack, 'TargetGroup', { vpc, port: 80 }); const listener = elbv2.ApplicationListener.fromLookup(stack, 'a', { @@ -1738,7 +1738,7 @@ describe('tests', () => { // GIVEN const identifierToken = 'SuperMagicToken'; const app = new cdk.App(); - const stack = new cdk.Stack(app, 'TestStack', { env: {account: '123456789012', region: 'us-east-1'} }); + const stack = new cdk.Stack(app, 'TestStack', { env: { account: '123456789012', region: 'us-east-1' } }); const vpc = new ec2.Vpc(stack, 'Stack'); const targetGroup = new elbv2.ApplicationTargetGroup(stack, 'TargetGroup', { vpc, port: 80 }); const listener = elbv2.ApplicationListener.fromLookup(stack, 'a', { From 923a1e8665432cc6fba26f3471d9fd6cff81b433 Mon Sep 17 00:00:00 2001 From: Andrew Hammond <445764+ahammond@users.noreply.github.com> Date: Fri, 5 Apr 2024 14:25:21 -0700 Subject: [PATCH 3/5] README update --- .../aws-elasticloadbalancingv2/README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/README.md b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/README.md index 34978410e072b..36f6ddf7d1be3 100644 --- a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/README.md +++ b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/README.md @@ -765,3 +765,18 @@ const targetGroup = elbv2.ApplicationTargetGroup.fromTargetGroupAttributes(this, const targetGroupMetrics: elbv2.IApplicationTargetGroupMetrics = targetGroup.metrics; // throws an Error() ``` + +## logicalIds on ExternalApplicationListener.addTargetGroups() and .addAction() + +Legacy behavior for the `addTargetGroups()` method did not follow the standard of adding +a `Rule` suffix to the logicalId. +If you have `ListenerRule`s deployed using the legacy behavior and are upgrading, +you will need to enable the `removeRuleSuffixFromLogicalId: true` property +so that CloudFormation will not attempt to replace your existing `ListenerRule`s. + +Similarly, if you have `ListenerRule`s deployed using the legacy behavior of `addTargetGroups()`, +which you need to switch over to being managed by the `addAction()` method, +then you will need to enable the `removeRuleSuffixFromLogicalId: true` property in the `addAction()` method. + +`ListenerRule`s have a unique `priority` for a given `Listener`. +Because the `priority` must be unique, CloudFormation will always fail when creating a new `ListenerRule` to replace the existing one, unless you change the `priority` as well as the logicalId. From 67d83c55204663b2cda477a26e10feb029e9ed27 Mon Sep 17 00:00:00 2001 From: Andrew Hammond <445764+ahammond@users.noreply.github.com> Date: Mon, 8 Apr 2024 11:39:09 -0700 Subject: [PATCH 4/5] retain legacy behavior for addTargetGroups --- .../aws-elasticloadbalancingv2/README.md | 12 ++++----- .../lib/alb/application-listener.ts | 22 +++++++++++++--- .../test/alb/listener.test.ts | 26 ++++++++++++------- 3 files changed, 40 insertions(+), 20 deletions(-) diff --git a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/README.md b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/README.md index 36f6ddf7d1be3..b79f330a17acb 100644 --- a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/README.md +++ b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/README.md @@ -768,13 +768,11 @@ const targetGroupMetrics: elbv2.IApplicationTargetGroupMetrics = targetGroup.met ## logicalIds on ExternalApplicationListener.addTargetGroups() and .addAction() -Legacy behavior for the `addTargetGroups()` method did not follow the standard of adding -a `Rule` suffix to the logicalId. -If you have `ListenerRule`s deployed using the legacy behavior and are upgrading, -you will need to enable the `removeRuleSuffixFromLogicalId: true` property -so that CloudFormation will not attempt to replace your existing `ListenerRule`s. - -Similarly, if you have `ListenerRule`s deployed using the legacy behavior of `addTargetGroups()`, +By default, the `addTargetGroups()` method does not follow the standard behavior +of adding a `Rule` suffix to the logicalId of the `ListenerRule` it creates. +If you are deploying new `ListenerRule`s using `addTargetGroups()` the recommendation +is to set the `removeRuleSuffixFromLogicalId: false` property. +If you have `ListenerRule`s deployed using the legacy behavior of `addTargetGroups()`, which you need to switch over to being managed by the `addAction()` method, then you will need to enable the `removeRuleSuffixFromLogicalId: true` property in the `addAction()` method. diff --git a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-listener.ts b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-listener.ts index d91955300e6b3..f0b7739264f66 100644 --- a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-listener.ts +++ b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-listener.ts @@ -620,12 +620,23 @@ abstract class ExternalApplicationListener extends Resource implements IApplicat * * It's possible to add conditions to the TargetGroups added in this way. * At least one TargetGroup must be added without conditions. + * + * NOTE: if you are deploying new infrastructure using this method, + * it is recommended to set the `removeRuleSuffixFromLogicalId: false` + * property so that the logicalId for the generated `ListenerRule` + * is consistent with other methods for managing `ListenerRule`s. + * + * If you have already deployed a `ListenerRule` using this method + * and need to migrate to using the more feature rich `addAction()` + * method, then you will need to set the `removeRuleSuffixFromLogicalId: true` + * property there to avoid having CloudFormation attempt to replace your resource. */ public addTargetGroups(id: string, props: AddApplicationTargetGroupsProps): void { checkAddRuleProps(props); if (props.priority !== undefined) { - const ruleId = props.removeRuleSuffixFromLogicalId ? id : id + 'Rule'; + const removeRuleSuffixFromLogicalId = props.removeRuleSuffixFromLogicalId ?? true; + const ruleId = removeRuleSuffixFromLogicalId ? id : id + 'Rule'; // New rule new ApplicationListenerRule(this, ruleId, { listener: this, @@ -665,6 +676,11 @@ abstract class ExternalApplicationListener extends Resource implements IApplicat * It is not possible to add a default action to an imported IApplicationListener. * In order to add actions to an imported IApplicationListener a `priority` * must be provided. + * + * If you previously deployed a `ListenerRule` using the `addTargetGroups()` method + * and need to migrate to using the more feature rich `addAction()` + * method, then you will need to set the `removeRuleSuffixFromLogicalId: true` + * property here to avoid having CloudFormation attempt to replace your resource. */ public addAction(id: string, props: AddApplicationActionProps): void { checkAddRuleProps(props); @@ -804,9 +820,9 @@ export interface AddApplicationTargetGroupsProps extends AddRuleProps { * * Legacy behavior did not include the `Rule` suffix on the logicalId of the generated `ListenerRule` * when generated by the `addTargetGroups()` method. - * This exists to allow backwards compatible behavior with `ListenerRule`s deployed by older versions of aws-cdk. + * This exists to allow new `ListenerRule`s to have consistent logicalIds. * - * @default - do not remove the logicalId `Rule` suffix + * @default true remove the logicalId `Rule` suffix */ readonly removeRuleSuffixFromLogicalId?: boolean; } diff --git a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/test/alb/listener.test.ts b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/test/alb/listener.test.ts index 1602665e63142..85b934f0692da 100644 --- a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/test/alb/listener.test.ts +++ b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/test/alb/listener.test.ts @@ -1699,16 +1699,21 @@ describe('tests', () => { }); describe('Rule suffix for logicalId', () => { + const identifierToken = 'SuperMagicToken'; interface TestCase { - readonly removeRuleSuffixFromLogicalId: boolean; + readonly removeRuleSuffixFromLogicalId?: boolean; + readonly expectedLogicalId: string; }; - const testCases: TestCase[] = [ - { removeRuleSuffixFromLogicalId: true }, - { removeRuleSuffixFromLogicalId: false }, + const nonDefaultTestCases: TestCase[] = [ + { removeRuleSuffixFromLogicalId: true, expectedLogicalId: identifierToken }, + { removeRuleSuffixFromLogicalId: false, expectedLogicalId: identifierToken + 'Rule' }, ]; - test.each(testCases)('addTargetGroups %s', ({ removeRuleSuffixFromLogicalId }) => { + test.each([ + // Default is to not have the `Rule` suffix, per legacy behavior. + { removeRuleSuffixFromLogicalId: undefined, expectedLogicalId: identifierToken }, + ...nonDefaultTestCases, + ])('addTargetGroups %s', ({ removeRuleSuffixFromLogicalId, expectedLogicalId }) => { // GIVEN - const identifierToken = 'SuperMagicToken'; const app = new cdk.App(); const stack = new cdk.Stack(app, 'TestStack', { env: { account: '123456789012', region: 'us-east-1' } }); const vpc = new ec2.Vpc(stack, 'Stack'); @@ -1728,15 +1733,17 @@ describe('tests', () => { }); // THEN - const expectedLogicalId = removeRuleSuffixFromLogicalId ? identifierToken : identifierToken + 'Rule'; const applicationListenerRule = listener.node.children.find((v)=> v.hasOwnProperty('conditions')); expect(applicationListenerRule).toBeDefined(); expect(applicationListenerRule!.node.id).toBe(expectedLogicalId); }); - test.each(testCases)('addAction %s', ({ removeRuleSuffixFromLogicalId }) => { + test.each([ + // Default is consistent, which means it has the `Rule` suffix. This means no change from legacy behavior + { removeRuleSuffixFromLogicalId: undefined, expectedLogicalId: identifierToken + 'Rule' }, + ...nonDefaultTestCases, + ])('addAction %s', ({ removeRuleSuffixFromLogicalId, expectedLogicalId }) => { // GIVEN - const identifierToken = 'SuperMagicToken'; const app = new cdk.App(); const stack = new cdk.Stack(app, 'TestStack', { env: { account: '123456789012', region: 'us-east-1' } }); const vpc = new ec2.Vpc(stack, 'Stack'); @@ -1756,7 +1763,6 @@ describe('tests', () => { }); // THEN - const expectedLogicalId = removeRuleSuffixFromLogicalId ? identifierToken : identifierToken + 'Rule'; const applicationListenerRule = listener.node.children.find((v)=> v.hasOwnProperty('conditions')); expect(applicationListenerRule).toBeDefined(); expect(applicationListenerRule!.node.id).toBe(expectedLogicalId); From 218631449e6550b7c9574f592eba55b2f9c8823a Mon Sep 17 00:00:00 2001 From: Andrew Hammond <445764+ahammond@users.noreply.github.com> Date: Wed, 17 Apr 2024 13:15:04 -0700 Subject: [PATCH 5/5] address comments --- .../lib/alb/application-listener.ts | 28 ++----------- .../test/alb/listener.test.ts | 42 +++---------------- 2 files changed, 9 insertions(+), 61 deletions(-) diff --git a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-listener.ts b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-listener.ts index f0b7739264f66..abc30dbd63714 100644 --- a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-listener.ts +++ b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-listener.ts @@ -620,25 +620,13 @@ abstract class ExternalApplicationListener extends Resource implements IApplicat * * It's possible to add conditions to the TargetGroups added in this way. * At least one TargetGroup must be added without conditions. - * - * NOTE: if you are deploying new infrastructure using this method, - * it is recommended to set the `removeRuleSuffixFromLogicalId: false` - * property so that the logicalId for the generated `ListenerRule` - * is consistent with other methods for managing `ListenerRule`s. - * - * If you have already deployed a `ListenerRule` using this method - * and need to migrate to using the more feature rich `addAction()` - * method, then you will need to set the `removeRuleSuffixFromLogicalId: true` - * property there to avoid having CloudFormation attempt to replace your resource. */ public addTargetGroups(id: string, props: AddApplicationTargetGroupsProps): void { checkAddRuleProps(props); if (props.priority !== undefined) { - const removeRuleSuffixFromLogicalId = props.removeRuleSuffixFromLogicalId ?? true; - const ruleId = removeRuleSuffixFromLogicalId ? id : id + 'Rule'; // New rule - new ApplicationListenerRule(this, ruleId, { + new ApplicationListenerRule(this, id, { listener: this, priority: props.priority, ...props, @@ -686,7 +674,7 @@ abstract class ExternalApplicationListener extends Resource implements IApplicat checkAddRuleProps(props); if (props.priority !== undefined) { - const ruleId = props.removeRuleSuffixFromLogicalId ? id : id + 'Rule'; + const ruleId = props.removeSuffix ? id : id + 'Rule'; // New rule // // TargetGroup.registerListener is called inside ApplicationListenerRule. @@ -815,16 +803,6 @@ export interface AddApplicationTargetGroupsProps extends AddRuleProps { * Target groups to forward requests to */ readonly targetGroups: IApplicationTargetGroup[]; - /** - * `ListenerRule`s have a `Rule` suffix on their logicalId by default. - * - * Legacy behavior did not include the `Rule` suffix on the logicalId of the generated `ListenerRule` - * when generated by the `addTargetGroups()` method. - * This exists to allow new `ListenerRule`s to have consistent logicalIds. - * - * @default true remove the logicalId `Rule` suffix - */ - readonly removeRuleSuffixFromLogicalId?: boolean; } /** @@ -847,7 +825,7 @@ export interface AddApplicationActionProps extends AddRuleProps { * * @default - use standard logicalId with the `Rule` suffix */ - readonly removeRuleSuffixFromLogicalId?: boolean; + readonly removeSuffix?: boolean; } /** diff --git a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/test/alb/listener.test.ts b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/test/alb/listener.test.ts index 85b934f0692da..0bc19b4d423eb 100644 --- a/packages/aws-cdk-lib/aws-elasticloadbalancingv2/test/alb/listener.test.ts +++ b/packages/aws-cdk-lib/aws-elasticloadbalancingv2/test/alb/listener.test.ts @@ -1701,48 +1701,18 @@ describe('tests', () => { describe('Rule suffix for logicalId', () => { const identifierToken = 'SuperMagicToken'; interface TestCase { - readonly removeRuleSuffixFromLogicalId?: boolean; + readonly removeSuffix?: boolean; readonly expectedLogicalId: string; }; const nonDefaultTestCases: TestCase[] = [ - { removeRuleSuffixFromLogicalId: true, expectedLogicalId: identifierToken }, - { removeRuleSuffixFromLogicalId: false, expectedLogicalId: identifierToken + 'Rule' }, + { removeSuffix: true, expectedLogicalId: identifierToken }, + { removeSuffix: false, expectedLogicalId: identifierToken + 'Rule' }, ]; - test.each([ - // Default is to not have the `Rule` suffix, per legacy behavior. - { removeRuleSuffixFromLogicalId: undefined, expectedLogicalId: identifierToken }, - ...nonDefaultTestCases, - ])('addTargetGroups %s', ({ removeRuleSuffixFromLogicalId, expectedLogicalId }) => { - // GIVEN - const app = new cdk.App(); - const stack = new cdk.Stack(app, 'TestStack', { env: { account: '123456789012', region: 'us-east-1' } }); - const vpc = new ec2.Vpc(stack, 'Stack'); - const targetGroup = new elbv2.ApplicationTargetGroup(stack, 'TargetGroup', { vpc, port: 80 }); - const listener = elbv2.ApplicationListener.fromLookup(stack, 'a', { - loadBalancerTags: { - some: 'tag', - }, - }); - - // WHEN - listener.addTargetGroups(identifierToken, { - conditions: [elbv2.ListenerCondition.pathPatterns(['/fake'])], - priority: 42, - targetGroups: [targetGroup], - removeRuleSuffixFromLogicalId, - }); - - // THEN - const applicationListenerRule = listener.node.children.find((v)=> v.hasOwnProperty('conditions')); - expect(applicationListenerRule).toBeDefined(); - expect(applicationListenerRule!.node.id).toBe(expectedLogicalId); - }); - test.each([ // Default is consistent, which means it has the `Rule` suffix. This means no change from legacy behavior - { removeRuleSuffixFromLogicalId: undefined, expectedLogicalId: identifierToken + 'Rule' }, + { removeSuffix: undefined, expectedLogicalId: identifierToken + 'Rule' }, ...nonDefaultTestCases, - ])('addAction %s', ({ removeRuleSuffixFromLogicalId, expectedLogicalId }) => { + ])('addAction %s', ({ removeSuffix, expectedLogicalId }) => { // GIVEN const app = new cdk.App(); const stack = new cdk.Stack(app, 'TestStack', { env: { account: '123456789012', region: 'us-east-1' } }); @@ -1759,7 +1729,7 @@ describe('tests', () => { action: elbv2.ListenerAction.weightedForward([{ targetGroup, weight: 1 }]), conditions: [elbv2.ListenerCondition.pathPatterns(['/fake'])], priority: 42, - removeRuleSuffixFromLogicalId, + removeSuffix, }); // THEN