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

[cli] cdk diff difficult to use programmatically #10417

Closed
2 tasks
pkwarren opened this issue Sep 17, 2020 · 5 comments · Fixed by #26297
Closed
2 tasks

[cli] cdk diff difficult to use programmatically #10417

pkwarren opened this issue Sep 17, 2020 · 5 comments · Fixed by #26297
Labels
effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. good first issue Related to contributions. See CONTRIBUTING.md p2 package/tools Related to AWS CDK Tools or CLI

Comments

@pkwarren
Copy link

pkwarren commented Sep 17, 2020

We're integrating CDK into a build pipeline and finding it difficult to differentiate between these possibilities:

  1. CDK diff detected no changes
  2. CDK diff detected changes
  3. CDK diff failed (wrong credentials, etc.)

When running cdk diff --fail, we can check the return code to differentiate case 1 vs. 2/3, however we can't differentiate between diff detecting changes and failing for some other type of error (they both return exitCode 1).

Additionally, it appears that we can't rely on whether output was printed to stdout or stderr - from a quick read through the code it appears diffs are printed to stderr along with errors as well.

Is there a supported mechanism to call the cdk diff command and differentiate the options above?

Use Case

We're integrating CDK into a build pipeline and would like to first determine if there are any differences before requiring an approval step for deployment.

Proposed Solution

A few options might be possible:

  • Return different exit codes with cdk diff --fail to differentiate "there are differences" from "there was an error calculating differences".
  • Use stdout for output of differences and stderr just for error reporting.

Other

  • 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change

This is a 🚀 Feature Request

@pkwarren pkwarren added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Sep 17, 2020
@github-actions github-actions bot added the package/tools Related to AWS CDK Tools or CLI label Sep 17, 2020
@rix0rrr
Copy link
Contributor

rix0rrr commented Sep 21, 2020

I agree distinguishing the error codes could be useful.

@rix0rrr rix0rrr added effort/small Small work item – less than a day of effort good first issue Related to contributions. See CONTRIBUTING.md p2 labels Sep 21, 2020
@SomayaB SomayaB removed the needs-triage This issue or PR still needs to be triaged. label Sep 21, 2020
@shadelocker
Copy link

I am happy to pick this issue with some guidance.

@rix0rrr rix0rrr removed their assignment Jun 3, 2021
@zhaoyi0113
Copy link

is there any update on this issue? it seems very useful feature.

@krzysztof-slowinski
Copy link
Contributor

For the part of using stdout for the output, please not that it is possible today by using --ci option:
cdk diff --ci --fail > diff.stdout 2> diff.stderr
Where the diffs will be now written to diff.stdout.

You can see the description of this option using cdk diff help:

--ci                 Force CI detection. If CI=true then logs will be sent
                       to stdout instead of stderr[boolean] [default: false]

@mergify mergify bot closed this as completed in #26297 Jul 21, 2023
mergify bot pushed a commit that referenced this issue Jul 21, 2023
…26297)

Reported issue with `diff` is that it treats the fail return status for cases when there are actual diffs, making it hard to know what happened with pipeline automations.

The proposed solution adds a logging statement with a similar format that is used for deploy (but here the total time is reported) specifying how many stacks have differences, as presented below. As a result, it will be possible to check in pipelines for this logging statement to correctly detect situation when there are no actual changes, when there are changes, and when there are failures, since on failures this statement will not be present:

Case of no changes:
✨  Number of stacks with differences: 0

Case of changes in 5 stacks:
✨  Number of stacks with differences: 5

Closes #10417.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@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.

bmoffatt pushed a commit to bmoffatt/aws-cdk that referenced this issue Jul 29, 2023
…ws#26297)

Reported issue with `diff` is that it treats the fail return status for cases when there are actual diffs, making it hard to know what happened with pipeline automations.

The proposed solution adds a logging statement with a similar format that is used for deploy (but here the total time is reported) specifying how many stacks have differences, as presented below. As a result, it will be possible to check in pipelines for this logging statement to correctly detect situation when there are no actual changes, when there are changes, and when there are failures, since on failures this statement will not be present:

Case of no changes:
✨  Number of stacks with differences: 0

Case of changes in 5 stacks:
✨  Number of stacks with differences: 5

Closes aws#10417.

----

*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
effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. good first issue Related to contributions. See CONTRIBUTING.md p2 package/tools Related to AWS CDK Tools or CLI
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants