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

feat(cli): cdk diff works for Nested Stacks #18207

Merged
merged 16 commits into from
Feb 3, 2022

Conversation

comcalvi
Copy link
Contributor

@comcalvi comcalvi commented Dec 29, 2021

cdk diff now compares all template objects (Resources, Outputs, etc) across nested stacks.

Closes #5722.


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

@gitpod-io
Copy link

gitpod-io bot commented Dec 29, 2021

@github-actions github-actions bot added the package/tools Related to AWS CDK Tools or CLI label Dec 29, 2021
@comcalvi comcalvi assigned skinny85 and unassigned rix0rrr Dec 29, 2021
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Dec 29, 2021
Copy link
Contributor

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

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

Nice work @comcalvi! While the experience is good, the code needs a few more iterations before we can merge it.

I think it's worth to think about the responsibilities here. I believe most of the problems with the code right now are because too much has been put in the CdkToolkit class. I think we need to spread the responsibilities around, so that the code in each class is smaller, and easier to understand.

packages/aws-cdk/lib/api/cloudformation-deployments.ts Outdated Show resolved Hide resolved
packages/aws-cdk/lib/api/cloudformation-deployments.ts Outdated Show resolved Hide resolved
packages/aws-cdk/lib/api/cloudformation-deployments.ts Outdated Show resolved Hide resolved
packages/aws-cdk/lib/cdk-toolkit.ts Outdated Show resolved Hide resolved
packages/aws-cdk/lib/cdk-toolkit.ts Outdated Show resolved Hide resolved
packages/aws-cdk/lib/cdk-toolkit.ts Outdated Show resolved Hide resolved
packages/aws-cdk/lib/cdk-toolkit.ts Outdated Show resolved Hide resolved
packages/aws-cdk/lib/cdk-toolkit.ts Outdated Show resolved Hide resolved
packages/aws-cdk/lib/cdk-toolkit.ts Outdated Show resolved Hide resolved
packages/aws-cdk/lib/cdk-toolkit.ts Outdated Show resolved Hide resolved
@comcalvi comcalvi requested a review from skinny85 January 4, 2022 23:57
Copy link
Contributor

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

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

This is shaping up better, but I think the production code needs some more polish.

Also, this is the experience I see when going from new sns.Topic(this, 'Topic'); to

    this.topic = new sns.Topic(this, 'Topic', {
      topicName: 'myFifoQueue',
      fifo: true,
      contentBasedDeduplication: true,
    });
Stack UsingNestedStacks
Resources
[~] AWS::CloudFormation::Stack SnsNestedStack.NestedStack/SnsNestedStack.NestedStackResource SnsNestedStackNestedStackSnsNestedStackNestedStackResourceAB4E8721 
 └─ [~] Resources
     └─ [~] .TopicBFC7AF6E:
         └─ [+] Added: .Properties

I don't think that's expected, right? (I would expect to see the values of the properties) Probably needs some work there too.

packages/aws-cdk/lib/cdk-toolkit.ts Outdated Show resolved Hide resolved
packages/aws-cdk/lib/api/cloudformation-deployments.ts Outdated Show resolved Hide resolved
packages/aws-cdk/lib/cdk-toolkit.ts Outdated Show resolved Hide resolved
packages/aws-cdk/lib/cdk-toolkit.ts Outdated Show resolved Hide resolved
packages/aws-cdk/lib/cdk-toolkit.ts Outdated Show resolved Hide resolved
packages/aws-cdk/lib/api/list-stack-resources.ts Outdated Show resolved Hide resolved
packages/aws-cdk/lib/api/list-stack-resources.ts Outdated Show resolved Hide resolved
packages/aws-cdk/lib/api/list-stack-resources.ts Outdated Show resolved Hide resolved
packages/aws-cdk/lib/cdk-toolkit.ts Outdated Show resolved Hide resolved
packages/aws-cdk/lib/cdk-toolkit.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

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

This is getting closer, but still needs some work.

The part I'm most unsure of is changing the formatObjectDiff() code, and how it changes the rendered diff, and whether the way we handle the nested stacks, by just jamming the entire template in place of the resource, will give us the correct classes from running diff that we need for hotswapping.

packages/@aws-cdk/cloudformation-diff/lib/format.ts Outdated Show resolved Hide resolved
packages/aws-cdk/lib/api/cloudformation-deployments.ts Outdated Show resolved Hide resolved
packages/aws-cdk/lib/api/cloudformation-deployments.ts Outdated Show resolved Hide resolved
packages/aws-cdk/lib/api/cloudformation-deployments.ts Outdated Show resolved Hide resolved
packages/aws-cdk/lib/api/cloudformation-deployments.ts Outdated Show resolved Hide resolved
packages/aws-cdk/lib/api/cloudformation-deployments.ts Outdated Show resolved Hide resolved
packages/aws-cdk/lib/api/cloudformation-deployments.ts Outdated Show resolved Hide resolved
packages/aws-cdk/lib/api/cloudformation-deployments.ts Outdated Show resolved Hide resolved
@comcalvi comcalvi changed the base branch from master to nija-at/jest-eks January 20, 2022 22:35
@comcalvi comcalvi changed the base branch from nija-at/jest-eks to master January 20, 2022 22:35
@comcalvi comcalvi closed this Jan 20, 2022
@comcalvi comcalvi reopened this Jan 20, 2022
Copy link
Contributor

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

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

Looks almost perfect! Just a few last finishing touches, and we will get this merged.

packages/aws-cdk/lib/api/cloudformation-deployments.ts Outdated Show resolved Hide resolved
packages/aws-cdk/lib/api/cloudformation-deployments.ts Outdated Show resolved Hide resolved
packages/aws-cdk/lib/api/cloudformation-deployments.ts Outdated Show resolved Hide resolved
packages/aws-cdk/lib/api/cloudformation-deployments.ts Outdated Show resolved Hide resolved
packages/aws-cdk/lib/api/cloudformation-deployments.ts Outdated Show resolved Hide resolved
@skinny85 skinny85 changed the title fix(cli): cdk diff compares template objects across nested stacks feat(cli): cdk diff works for Nested Stacks Feb 2, 2022
@skinny85 skinny85 added the pr-linter/exempt-readme The PR linter will not require README changes label Feb 2, 2022
Copy link
Contributor

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

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

Looks almost perfect 🙂

packages/aws-cdk/lib/api/cloudformation-deployments.ts Outdated Show resolved Hide resolved
@@ -104,7 +104,7 @@ export class CdkToolkit {
// Compare N stacks against deployed templates
for (const stack of stacks.stackArtifacts) {
stream.write(format('Stack %s\n', chalk.bold(stack.displayName)));
const currentTemplate = await this.props.cloudFormation.readCurrentTemplate(stack);
const currentTemplate = await this.props.cloudFormation.readCurrentTemplateWithNestedStacks(stack); // TODO; renmae
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we remove the ToDo then...? 🙂

Copy link
Contributor

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

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

👍

@mergify
Copy link
Contributor

mergify bot commented Feb 3, 2022

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: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: 3bb10f5
  • 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 1337b24 into aws:master Feb 3, 2022
@mergify
Copy link
Contributor

mergify bot commented Feb 3, 2022

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).

kornicameister added a commit to kornicameister/aws-cdk that referenced this pull request Feb 6, 2022
* origin/master: (27 commits)
  chore(eks): deprecate older versions of EKS (aws#18842)
  fix(tooling): update vscode devcontainer image (aws#18455)
  chore: npm-check-updates && yarn upgrade (aws#18832)
  chore(docs): Fix broken md links (aws#18384)
  chore(lambda-layer-awscli): install awscli with pip and requirements.txt (aws#18800)
  fix(aws-appsync): Strip unsupported characters from Lambda DataSource (aws#18765)
  feat(cfnspec): cloudformation spec v55.0.0 (aws#18827)
  docs(cfnspec): update CloudFormation documentation (aws#18826)
  chore(cxapi): plugin context provider limited by cx schema (aws#18709)
  feat(iotevents): add grant method to Input class (aws#18617)
  chore(cx-api): break circular dependencies (aws#18767)
  docs(core): clarify that `addOverride` does not change property casing (aws#18687)
  feat(s3-deployment): deploy data with deploy-time values (aws#18659)
  docs(cfnspec): update CloudFormation documentation (aws#18808)
  feat(cli): `cdk diff` works for Nested Stacks (aws#18207)
  docs(cfnspec): update CloudFormation documentation (aws#18783)
  chore(lambda-layer-awscli): add update mechanism for AWS CLI (aws#18780)
  chore(release): 1.143.0
  feat(fsx): add support for FSx Lustre Persistent_2 deployment type (aws#18626)
  feat(amplify): support performance mode in Branch (aws#18598)
  ...
TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this pull request Feb 21, 2022
`cdk diff` now compares all template objects (Resources, Outputs, etc) across nested stacks.

Closes aws#5722.

----

*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. package/tools Related to AWS CDK Tools or CLI pr-linter/exempt-readme The PR linter will not require README changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cdk diff does not work with nested stacks
4 participants