Skip to content

ElasticLoadBalancerV2: migration to addAction() from addTargetGroups() fails because of logicalId change #29496

@ahammond

Description

@ahammond

Describe the bug

We need to access functionality not available in the ApplicationListener.addTargetGroups() helper method (specifically, ListenerAction.weightedForward()). To do this, we've changed from

Old code

      this.httpsListener.addTargetGroups(this.serviceRoot, {
        conditions: [ListenerCondition.pathPatterns(this.injectionPaths)],
        priority: this.injectionPriority,
        targetGroups: [this.taskTargetGroup],
      });

New code

      this.httpsListener.addAction(this.serviceRoot, {
        action: ListenerAction.weightedForward(this.weightedTargetGroups),        
        conditions: [ListenerCondition.pathPatterns(this.injectionPaths)],
        priority: this.injectionPriority,
      });

However, when I do a cdk diff of the stack, I get

Resources
[-] AWS::ElasticLoadBalancingV2::ListenerRule UsQaQaUsWest26/ClipsServiceInstance/https/--clips-service-v3 httpsclipsservicev36BE2E78C destroy
[+] AWS::ElasticLoadBalancingV2::ListenerRule UsQaQaUsWest26/ClipsServiceInstance/https/--clips-service-v3RuleRule httpsclipsservicev3RuleRule772FC4D6 

I note that https://github.com/aws/aws-cdk/blob/050a305d6be65df7e5f1e17668cbf512ead34d23/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-listener.ts#L675-L676 is adding the Rule suffix to the logicalId, which is driving a replacement rather than update.

Expected Behavior

We should be able to go from the helper method to the underlying support method without a logicalId change.

Current Behavior

Because of the logicalId change, Cfn wants to replace our ListenerRules. Create before destroy means that Cfn tries to create a new ListenerRule with the same priority as the existing ListnerRule, which fails, blocking upgrade path.

Reproduction Steps

Sigh.

Possible Solution

Add a feature flag for not adding the Rule suffix to the logicalId in the addAction() method.

Additional Information/Context

No response

CDK CLI Version

2.100.0 (build e1b5c77)

Framework Version

No response

Node.js Version

20.5.1

OS

MacOS

Language

TypeScript

Language Version

5.3.3

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-elasticloadbalancingv2Related to Amazon Elastic Load Balancing V2bugThis issue is a bug.effort/mediumMedium work item – several days of effortp2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions