Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws-cdk-lib: Stack names broken after prefix changes on 2.74.0 version #25130

Closed
malaquf opened this issue Apr 14, 2023 · 2 comments · Fixed by #25163
Closed

aws-cdk-lib: Stack names broken after prefix changes on 2.74.0 version #25130

malaquf opened this issue Apr 14, 2023 · 2 comments · Fixed by #25163
Labels
@aws-cdk/core Related to core CDK functionality aws-cdk-lib Related to the aws-cdk-lib package bug This issue is a bug. effort/medium Medium work item – several days of effort management/tracking Issues that track a subject or multiple issues p0

Comments

@malaquf
Copy link

malaquf commented Apr 14, 2023

Please add your +1 👍 to let us know you have encountered this

Status: RESOLVED

Overview:

The CDK now attempts to deploy duplicated stacks with slight different names in some cases after changes done at https://github.com/aws/aws-cdk/pull/24443/files.

This happens because of prefixes automatically created by Stages and Stacks created within Stacks, and before the change, the prefixes were not sanitised by removeNonAllowedSpecialCharacters().

This breaking change requires huge effort in productive systems where unique resources are created within such stacks (e.g.: databases), so a fix (maybe a feature flag?) would be very much appreciated.

Workaround:

Upgrade to 2.75.1

Solution:

Reverted the PR that made the change.

Related Issues:

Original Issue:

Describe the bug

The CDK now attempts to deploy duplicated stacks with slight different names in some cases after changes done at https://github.com/aws/aws-cdk/pull/24443/files.

This happens because of prefixes automatically created by Stages and Stacks created within Stacks, and before the change, the prefixes were not sanitised by removeNonAllowedSpecialCharacters().

This breaking change requires huge effort in productive systems where unique resources are created within such stacks (e.g.: databases), so a fix (maybe a feature flag?) would be very much appreciated.

Expected Behavior

Compatibility with prefixes on stack names created previously to 2.74.0 release.
Eg.: test-AuthorizationServerStackAuthorizationServerNetworkStack

Current Behavior

Separator is removed from prefixes at removeNonAllowedSpecialCharacters().
E.g.: testAuthorizationServerStackAuthorizationServerNetworkStack

Reproduction Steps

test('Should not modify stage prefix', () => {
    // WHEN
    const app = new App();
    new MyStage(app, 'test');
    let result = app.synth();
    console.log(result);
});

class MyStage extends Stage {
    constructor(scope: Construct, id: string) {
        super(scope, id);
        new AuthorizationServerStack(this, 'AuthorizationServerStack', {
            stackName: 'AuthorizationServerStack'
        });
    }
}

class AuthorizationServerStack extends Stack {
    constructor(scope: Construct, id: string, props?: StackProps) {
        super(scope, id, props);
        let bogusStack = new BogusStack(this, 'AuthorizationServerNetworkStack');
        // THEN
        expect(bogusStack.stackName).toEqual('test-AuthorizationServerStackAuthorizationServerNetworkStack');
    }
}

class BogusStack extends Stack {
    constructor(scope: Construct, id: string, props?: StackProps) {
        super(scope, id, props);

        new CfnResource(this, 'Resource', {
            type: 'CDK::Test::Resource',
        });
    }
}

Possible Solution

It seems to me the only possible compatible solution at this point (after 2.74.0 release) would be to introduce a feature flag/param for the stacks. Otherwise, the next version might break stacks created with stripped chars.

Additional Information/Context

This bug happens if options.prefix && components.length > 1, and prefixes contain special chars (as the dash introduced by stages).

CDK CLI Version

2.74.0

Framework Version

No response

Node.js Version

18

OS

MacOS

Language

Typescript

Language Version

No response

Other information

Issue introduced with changes from https://github.com/aws/aws-cdk/pull/24443/files which should fix #23628

@malaquf malaquf added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Apr 14, 2023
@github-actions github-actions bot added the aws-cdk-lib Related to the aws-cdk-lib package label Apr 14, 2023
@pahud
Copy link
Contributor

pahud commented Apr 17, 2023

Yes I can confirm the dash(-) is now removed since 2.74.0.

@pahud pahud added p1 effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Apr 17, 2023
@kellertk kellertk added p0 and removed p1 labels Apr 17, 2023
@mergify mergify bot closed this as completed in #25163 Apr 17, 2023
mergify bot pushed a commit that referenced this issue Apr 17, 2023
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

comcalvi pushed a commit that referenced this issue Apr 18, 2023
@comcalvi comcalvi added management/tracking Issues that track a subject or multiple issues @aws-cdk/core Related to core CDK functionality labels Apr 20, 2023
@comcalvi comcalvi pinned this issue Apr 20, 2023
mergify bot pushed a commit to cdklabs/aws-cdk-notices that referenced this issue Apr 21, 2023
CLI notice for #25130. Stack names have been modified in a breaking way if they use special characters.
@udaypant udaypant unpinned this issue Apr 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/core Related to core CDK functionality aws-cdk-lib Related to the aws-cdk-lib package bug This issue is a bug. effort/medium Medium work item – several days of effort management/tracking Issues that track a subject or multiple issues p0
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants