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

fix(core): overrideLogicalId validation #29708

Merged
merged 4 commits into from
Jun 17, 2024

Conversation

nmussy
Copy link
Contributor

@nmussy nmussy commented Apr 3, 2024

Issue # (if applicable)

Closes #29701

Reason for this change

Calling overrideLogicalId on a Construct with an invalid logical ID (docs) would not throw an error at synthesis time. CloudFormation would

Description of changes

  • Validate overrideLogicalId (must not be empty, must not be over 255 characters, must match /^[A-Za-z0-9]+$/
  • Document exceptions with @error JSDoc tags

Description of how you validated changes

I've added unit tests, integration tests should not be necessary

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@github-actions github-actions bot added distinguished-contributor [Pilot] contributed 50+ PRs to the CDK bug This issue is a bug. effort/small Small work item – less than a day of effort p2 labels Apr 3, 2024
@aws-cdk-automation aws-cdk-automation requested a review from a team April 3, 2024 19:03
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

@nmussy
Copy link
Contributor Author

nmussy commented Apr 3, 2024

Exemption Request: This is just a synth time check, CloudFormation is already failing if unhappy with the logical ID

@aws-cdk-automation aws-cdk-automation added the pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback. label Apr 3, 2024
@nmussy nmussy marked this pull request as ready for review April 3, 2024 19:38
@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Apr 3, 2024
@TheRealAmazonKendra TheRealAmazonKendra added the pr-linter/exempt-integ-test The PR linter will not require integ test changes label Apr 8, 2024
@aws-cdk-automation aws-cdk-automation dismissed their stale review April 8, 2024 22:19

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

Copy link
Contributor

@TheRealAmazonKendra TheRealAmazonKendra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm hesitant to accept this but am open to conversation about it. If CloudFormation updates their requirements here, it would create more manual work on our end. Is the error message unclear enough at deploy time that this provides a major quality of life improvement for users?

@aws-cdk-automation aws-cdk-automation removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Apr 8, 2024
@nmussy
Copy link
Contributor Author

nmussy commented Apr 9, 2024

The CloudFormation deploy time message is absolutely clear about this issue, this is a duplicated synth time check

The main issue is the difference in how the CDK resolves regular construct generated logical IDs vs overrides. The IDs provided to the constructor are slugified, but not the overrides:

new cdk.CfnOutput(this, 'Invalid construct name', { 
  value: 'value', 
});

new cdk.CfnOutput(this, 'Output', { 
  value: 'value', 
}).overrideLogicalId('Another invalid construct name');
$ npm run cdk synth

Outputs:
  Invalidconstructname:
    Value: value
  Another invalid construct name:
    Value: value

I don't think changing this behavior to also slugify the override is warranted, to leave the escape hatch as is. Giving the user an early warning is probably best.

This PR would also prevent an issue like #29700 from reoccurring. An integration test would have caught it, but a unit test would have been sufficient with this change.

@aws-cdk-automation
Copy link
Collaborator

This PR has been in the CHANGES REQUESTED state for 3 weeks, and looks abandoned. To keep this PR from being closed, please continue work on it. If not, it will automatically be closed in a week.

@nmussy
Copy link
Contributor Author

nmussy commented Apr 30, 2024

@TheRealAmazonKendra Bump

@aws-cdk-automation
Copy link
Collaborator

This PR has been deemed to be abandoned, and will be automatically closed. Please create a new PR for these changes if you think this decision has been made in error.

@aws-cdk-automation aws-cdk-automation added the closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. label May 7, 2024
@nmussy
Copy link
Contributor Author

nmussy commented May 7, 2024

@TheRealAmazonKendra Bunping again 😅

@kaizencc kaizencc reopened this Jun 10, 2024
@kaizencc kaizencc added pr-linter/do-not-close The PR linter will not close this PR while this label is present and removed closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. labels Jun 10, 2024
Copy link
Contributor

@GavinZZ GavinZZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I'm also a fan of throwing error at synthesize time to save some user time and we can control the error msg on our side to make sure it's clear.

@GavinZZ GavinZZ dismissed TheRealAmazonKendra’s stale review June 17, 2024 17:45

Dismissing stale reviews.

Copy link
Contributor

mergify bot commented Jun 17, 2024

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

Copy link
Contributor

mergify bot commented Jun 17, 2024

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 6e210d0
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit b196b13 into aws:main Jun 17, 2024
9 checks passed
Copy link
Contributor

mergify bot commented Jun 17, 2024

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

scorbiere pushed a commit to scorbiere/aws-cdk that referenced this pull request Jun 20, 2024
### Issue # (if applicable)

Closes aws#29701

### Reason for this change

Calling `overrideLogicalId` on a `Construct` with an invalid logical ID ([docs](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/resources-section-structure.html#resources-section-structure-logicalid)) would not throw an error at synthesis time. CloudFormation would 

### Description of changes

* Validate `overrideLogicalId` (must not be empty, must not be over 255 characters, must match `/^[A-Za-z0-9]+$/`
* Document exceptions with `@error` JSDoc tags

### Description of how you validated changes

I've added unit tests, integration tests should not be necessary

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
sarangarav pushed a commit to sarangarav/aws-cdk that referenced this pull request Jun 21, 2024
### Issue # (if applicable)

Closes aws#29701

### Reason for this change

Calling `overrideLogicalId` on a `Construct` with an invalid logical ID ([docs](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/resources-section-structure.html#resources-section-structure-logicalid)) would not throw an error at synthesis time. CloudFormation would 

### Description of changes

* Validate `overrideLogicalId` (must not be empty, must not be over 255 characters, must match `/^[A-Za-z0-9]+$/`
* Document exceptions with `@error` JSDoc tags

### Description of how you validated changes

I've added unit tests, integration tests should not be necessary

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
mazyu36 pushed a commit to mazyu36/aws-cdk that referenced this pull request Jun 22, 2024
### Issue # (if applicable)

Closes aws#29701

### Reason for this change

Calling `overrideLogicalId` on a `Construct` with an invalid logical ID ([docs](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/resources-section-structure.html#resources-section-structure-logicalid)) would not throw an error at synthesis time. CloudFormation would 

### Description of changes

* Validate `overrideLogicalId` (must not be empty, must not be over 255 characters, must match `/^[A-Za-z0-9]+$/`
* Document exceptions with `@error` JSDoc tags

### Description of how you validated changes

I've added unit tests, integration tests should not be necessary

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@jnawk
Copy link

jnawk commented Jun 27, 2024

How could this possibly be correct? CloudFormation doesn't define what constitutes a valid logical ID outside of the Resources section of a template - eg the conditions section allows logical IDs that are snake_case - See @mjgoble 's issue linked above for an example of why merging this PR was the WRONG thing to do.

TheRealAmazonKendra added a commit that referenced this pull request Jun 27, 2024
mergify bot pushed a commit that referenced this pull request Jun 27, 2024
scanlonp pushed a commit that referenced this pull request Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. distinguished-contributor [Pilot] contributed 50+ PRs to the CDK effort/small Small work item – less than a day of effort p2 pr-linter/do-not-close The PR linter will not close this PR while this label is present pr-linter/exempt-integ-test The PR linter will not require integ test changes pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

core: missing logical ID override validation
7 participants