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(cfn-include): cfn-include fails in monocdk #11595

Merged
merged 7 commits into from
Dec 11, 2020

Conversation

skinny85
Copy link
Contributor

The cloudformation-include module generates a big JSON
file at build time that contains the mapping from the CloudFormation resource type
to the fully-qualified class name of the corresponding L1
(something like "AWS::S3::Bucket": "@aws-cdk/aws-s3.CfnBucket").
The problem is that mono-CDK re-packages all of the per-service
modules into one big module,
and requiring the module from the mapping fails for it.

Solve the issue by adding an additional build step in mono-CDK that re-writes that file with the mapping values changed
(to something like "monocdk/aws-s3.CfnBucket").

Fixes #11342


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

@skinny85 skinny85 requested a review from nija-at November 19, 2020 21:47
@gitpod-io
Copy link

gitpod-io bot commented Nov 19, 2020

@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Nov 19, 2020
@skinny85
Copy link
Contributor Author

I unfortunately only tested this change manually. I tried adding a simple unit test for cloudformation-include in the monocdk package, but unfortunately it passes even without any changes, as the @aws-cdk/aws-<service> modules are all present in the top-level node_modules 😕.

@nija-at let me know if this solution makes sense. If yes, we can also add it to the aws-cdk-lib package on the v2-main branch.

@skinny85 skinny85 added the pr-linter/exempt-test The PR linter will not require test changes label Nov 19, 2020
Copy link
Contributor

@nija-at nija-at left a comment

Choose a reason for hiding this comment

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

We need to identify a way to test this. We can't afford for this to regress if we decide to change something in aws-cdk-lib and it breaks cfn-include again.

Can we add an integration test instead?

@nija-at let me know if this solution makes sense. If yes, we can also add it to the aws-cdk-lib package on the v2-main branch.

Add it into the aws-cdk-lib package in master and it will automatically get merged into v2-main

@nija-at nija-at changed the title fix(cfn-include): cfn-include fails in mono-CDK fix(cfn-include): cfn-include fails in monocdk Nov 20, 2020
@skinny85 skinny85 force-pushed the fix/cfn-include-monocdk branch from d7353d9 to fe4e907 Compare November 24, 2020 00:20
@skinny85
Copy link
Contributor Author

@nija-at after some digging and trail-and-error, I was able to add a unit test in monocdk that correctly checks this (I looked into an integration test, but it looked very painful).

Let me know if this solution works for you!

@skinny85 skinny85 removed the pr-linter/exempt-test The PR linter will not require test changes label Nov 24, 2020
Copy link
Contributor

@nija-at nija-at left a comment

Choose a reason for hiding this comment

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

Can we move this into a separate package under the tools/ folder so that it can be reused across monocdk and aws-cdk-lib?

ubergen might be a good spot but would be nice to have a separate one so it's kept separate and decoupled.

@skinny85 skinny85 force-pushed the fix/cfn-include-monocdk branch 2 times, most recently from 9da4ce9 to 99c4666 Compare November 26, 2020 00:19
@skinny85
Copy link
Contributor Author

Can we move this into a separate package under the tools/ folder so that it can be reused across monocdk and aws-cdk-lib?

ubergen might be a good spot but would be nice to have a separate one so it's kept separate and decoupled.

@nija-at done! Please give the PR another look 🙂

@skinny85 skinny85 requested a review from nija-at November 26, 2020 00:20
packages/monocdk/package.json Outdated Show resolved Hide resolved
packages/monocdk/test/cfn-include/cfn-include.test.ts Outdated Show resolved Hide resolved
@skinny85 skinny85 force-pushed the fix/cfn-include-monocdk branch from 99c4666 to ac3ed43 Compare December 1, 2020 00:04
@skinny85 skinny85 requested a review from nija-at December 1, 2020 00:04
@skinny85
Copy link
Contributor Author

skinny85 commented Dec 1, 2020

Keep the name terse. just call it cfninclude-rewriter.

This has been done. @nija-at please take another look!

Copy link
Contributor

@nija-at nija-at left a comment

Choose a reason for hiding this comment

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

At this point, this discussion is likely more effective and faster to converge synchronously.

tools/cfninclude-rewriter/bin/cfninclude-rewriter.ts Outdated Show resolved Hide resolved
packages/monocdk/test/cfn-include/cfn-include.test.ts Outdated Show resolved Hide resolved
@skinny85 skinny85 force-pushed the fix/cfn-include-monocdk branch from ac3ed43 to 1d60f92 Compare December 8, 2020 22:54
@skinny85
Copy link
Contributor Author

skinny85 commented Dec 8, 2020

@nija-at I've re-structured the solution completely, by moving the logic of re-writing the file to ubergen, and the test from a unit test to an integ test. Please re-review!

@skinny85 skinny85 requested a review from nija-at December 8, 2020 22:55
@skinny85 skinny85 force-pushed the fix/cfn-include-monocdk branch from 1d60f92 to ef41589 Compare December 8, 2020 22:59
Copy link
Contributor

@nija-at nija-at left a comment

Choose a reason for hiding this comment

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

Much better set of changes than the previous iteration. Thanks for taking the time to fix this.

These comments are less intrusive.

packages/aws-cdk/test/integ/cli/monocdk.integtest.js Outdated Show resolved Hide resolved
packages/aws-cdk/test/integ/cli/.gitignore Outdated Show resolved Hide resolved
packages/aws-cdk/test/integ/cli/monocdk.integtest.js Outdated Show resolved Hide resolved
The cloudformation-include module generates a big JSON
file at build time that contains the mapping from the CloudFormation resource type
to the fully-qualified class name of the corresponding L1
(something like "AWS::S3::Bucket": "@aws-cdk/aws-s3.CfnBucket").
The problem is that mono-CDK re-packages all of the per-service
modules into one big module,
and requiring the module from the mapping fails for it.

Solve the issue by adding an additional build step in ubergen that re-writes that file with the mapping values changed
(to something like "monocdk/aws-s3.CfnBucket").

Fixes aws#11342
@skinny85 skinny85 force-pushed the fix/cfn-include-monocdk branch from ef41589 to 8c3ad08 Compare December 11, 2020 02:20
@nija-at nija-at added the pr/do-not-merge This PR should not be merged at this time. label Dec 11, 2020
Copy link
Contributor

@nija-at nija-at left a comment

Choose a reason for hiding this comment

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

LGTM! Some minor comments below.

You will need to make changes to cdk-ops to add this integration test for monocdk to cdk-master and aws-cdk-lib to v2-main.

packages/aws-cdk/test/integ/cli/bootstrapping.integtest.ts Outdated Show resolved Hide resolved
packages/aws-cdk/test/integ/common/jest-test.bash Outdated Show resolved Hide resolved
@skinny85 skinny85 removed the pr/do-not-merge This PR should not be merged at this time. label Dec 11, 2020
@mergify
Copy link
Contributor

mergify bot commented Dec 11, 2020

Thank you for contributing! Your pull request will be updated from master 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: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: 70e52a0
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

@mergify
Copy link
Contributor

mergify bot commented Dec 11, 2020

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

@mergify mergify bot merged commit 45e43f2 into aws:master Dec 11, 2020
skinny85 added a commit that referenced this pull request Dec 11, 2020
The changes from #11595 moved some helper TypeScript files around.
When running without compiling first (like in the pipeline, or in the canaries),
we need to install the dependencies those files need manually.
Unfortunately, after the move, they are now installed in a sibling directory,
not in any ancestor directory,
and so `require`ing them fails.
mergify bot pushed a commit that referenced this pull request Dec 11, 2020
…tor (#12029)

The changes from #11595 moved some helper TypeScript files around.
When running without compiling first (like in the pipeline, or in the canaries),
we need to install the dependencies those files need manually.
Unfortunately, after the move, they are now installed in a sibling directory,
not in any ancestor directory,
and so `require`ing them fails.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@skinny85 skinny85 deleted the fix/cfn-include-monocdk branch December 11, 2020 23:36
flochaz pushed a commit to flochaz/aws-cdk that referenced this pull request Jan 5, 2021
The cloudformation-include module generates a big JSON
file at build time that contains the mapping from the CloudFormation resource type
to the fully-qualified class name of the corresponding L1
(something like "AWS::S3::Bucket": "@aws-cdk/aws-s3.CfnBucket").
The problem is that mono-CDK re-packages all of the per-service
modules into one big module,
and requiring the module from the mapping fails for it.

Solve the issue by adding an additional build step in mono-CDK that re-writes that file with the mapping values changed
(to something like "monocdk/aws-s3.CfnBucket").

Fixes aws#11342

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
flochaz pushed a commit to flochaz/aws-cdk that referenced this pull request Jan 5, 2021
…tor (aws#12029)

The changes from aws#11595 moved some helper TypeScript files around.
When running without compiling first (like in the pipeline, or in the canaries),
we need to install the dependencies those files need manually.
Unfortunately, after the move, they are now installed in a sibling directory,
not in any ancestor directory,
and so `require`ing them fails.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
skinny85 added a commit to skinny85/aws-cdk that referenced this pull request Jan 28, 2021
When we did the changes to fix cloudformation-include in aws#11595,
we did not account for the fact that the `@aws-cdk/core` is not mapped to `uberpackage/core`,
but instead just to the `uberpackage` root namespace.

Special-case the `@aws-cdk/core` module in ubergen when transforming the `cfn-types-2-classes.json` file.
mergify bot pushed a commit that referenced this pull request Jan 31, 2021
When we did the changes to fix cloudformation-include in #11595,
we did not account for the fact that the `@aws-cdk/core` is not mapped to `uberpackage/core`,
but instead just to the `uberpackage` root namespace.

Special-case the `@aws-cdk/core` module in ubergen when transforming the `cfn-types-2-classes.json` file.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
NovakGu pushed a commit to NovakGu/aws-cdk that referenced this pull request Feb 18, 2021
…12758)

When we did the changes to fix cloudformation-include in aws#11595,
we did not account for the fact that the `@aws-cdk/core` is not mapped to `uberpackage/core`,
but instead just to the `uberpackage` root namespace.

Special-case the `@aws-cdk/core` module in ubergen when transforming the `cfn-types-2-classes.json` file.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[@aws-cdk/cloudformation-include] CfnInclude not working with MonoCDK
3 participants