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 always reports diff if resource has non-ASCII characters #10523

Closed
idm-ryou opened this issue Sep 25, 2020 · 7 comments · Fixed by #25912
Closed

[cli] cdk diff always reports diff if resource has non-ASCII characters #10523

idm-ryou opened this issue Sep 25, 2020 · 7 comments · Fixed by #25912
Labels
blocked Work is blocked on this issue for this codebase. Other labels or comments may indicate why. bug This issue is a bug. effort/medium Medium work item – several days of effort needs-cfn This issue is waiting on changes to CloudFormation before it can be addressed. p1 package/tools Related to AWS CDK Tools or CLI

Comments

@idm-ryou
Copy link

idm-ryou commented Sep 25, 2020

cdk diff always reports diff if resource has non-ASCII characters.

Reproduction Steps

import * as cdk from "@aws-cdk/core";
import * as codebuild from "@aws-cdk/aws-codebuild";

const app = new cdk.App();
const stack = new cdk.Stack(app, "stack1");
new codebuild.Project(stack, "FooProject", {
  buildSpec: codebuild.BuildSpec.fromObject({
    version: "0.2",
    phases: {
      build: {
        commands: ["echo こんにちは"], // "Hello" in Japanese
      },
    },
  }),
});
$ cdk --version
1.63.0 (build 7a68125)

$ cdk deploy stack1 --require-approval=never
stack1: deploying...
<snip>
 ✅  stack1

$ cdk diff stack1
Stack stack1
Resources
[~] AWS::CodeBuild::Project FooProject FooProject9FE653E4 
 └─ [~] Source
     └─ [~] .BuildSpec:
         ├─ [-] {
  "version": "0.2",
  "phases": {
    "build": {
      "commands": [
        "echo ?????"
      ]
    }
  }
}
         └─ [+] {
  "version": "0.2",
  "phases": {
    "build": {
      "commands": [
        "echo こんにちは"
      ]
    }
  }
}

What did you expect to happen?

cdk diff reports no diff, when resources are in sync.

What actually happened?

cdk diff always reports diff, even when resources are in sync.

Environment

  • CLI Version : 1.63.0
  • Framework Version: 1.63.0
  • Node.js Version: v12.18.4
  • OS : Linux (Docker container)
  • Language (Version): all (I guess...)

Other

Guessing from its behavior, it seems like correct encoding(UTF-8?) is not specified while fetching current template from CloudFormation. So that the non-ASCII characters are converted to the "?" character and treated as if it is having diffs.


This is 🐛 Bug Report

@idm-ryou idm-ryou added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Sep 25, 2020
@SomayaB SomayaB changed the title [cli or core] cdk diff always reports diff if resource has non-ASCII characters [cli] cdk diff always reports diff if resource has non-ASCII characters Sep 25, 2020
@github-actions github-actions bot added the package/tools Related to AWS CDK Tools or CLI label Sep 25, 2020
@rix0rrr
Copy link
Contributor

rix0rrr commented Oct 2, 2020

I don't believe it's possible to specify the encoding when retrieving a stack template. Is it?

@rix0rrr rix0rrr added effort/medium Medium work item – several days of effort p1 labels Oct 2, 2020
@SomayaB SomayaB removed the needs-triage This issue or PR still needs to be triaged. label Oct 3, 2020
@kaeraali-flutterint
Copy link

This also appears to affect SynthUtils.toCloudFormation in @aws-cdk/assert, but I haven't looked at whether it is the same root cause.

@rix0rrr rix0rrr added blocked Work is blocked on this issue for this codebase. Other labels or comments may indicate why. needs-cfn This issue is waiting on changes to CloudFormation before it can be addressed. labels Feb 24, 2022
@Amakata
Copy link

Amakata commented Jun 1, 2022

I don't believe it's possible to specify the encoding when retrieving a stack template. Is it?

I think cloudformation template encoding is utf8.
but I seem cloudformation API(aws cloudformation get-template) don't support utf8 string.
"aws cloudformation get-template" has no encoding option.

@peterwoodworth
Copy link
Contributor

If anyone is interested in this feature, I recommend opening an issue in Cloudformation coverage roadmap

@idm-ryou
Copy link
Author

idm-ryou commented Jun 22, 2022

If anyone is interested in this feature, I recommend opening an issue in Cloudformation coverage roadmap

Done.
aws-cloudformation/cloudformation-coverage-roadmap#1220

@peterwoodworth
Copy link
Contributor

Thanks all, closing in favor of #25309

@github-actions
Copy link

github-actions bot commented Jun 9, 2023

⚠️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.

mergify bot pushed a commit that referenced this issue Jun 15, 2023
I am reopening this from #25525

and following up on my comments here:
#24557 (comment)
#24557 (comment)
#25008 (comment)
#25008 (comment)
#25008 (comment)
#25008 (comment)
#25008 (comment)
#25008 (comment)
#25525 (comment)
#25525 (comment)
🫠 #25525 (comment) 🫠

---

Fixes #25309
Fixes #22203
Fixes #20212
Fixes #13634
Fixes #10523
Fixes #10219
See also: aws-cloudformation/cloudformation-coverage-roadmap#1220
See also: aws-cloudformation/cloudformation-coverage-roadmap#814

---

👻 I have retitled this PR as a `chore` instead of a `fix` because @aws-cdk-automation keeps closing my PRs as abandoned even though they are clearly not abandoned.

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

---

@otaviomacedo @rix0rrr @TheRealAmazonKendra - I'm happy to adjust the approach, add more tests, or do what else needs to be done. I'm not getting any feedback from the team so I'm not sure how to proceed. The diff noise with non-ASCII information in cdk diff makes it difficult to find meaningful changes to our stacks.

🗿🗞️📬 **Crucially, this change only affects the CLI output and therefore an integration test isn't possible.**

---

CloudFormation's `GetStackTemplate` irrecoverably mangles any character not in the 7-bit ASCII range. This causes noisy output from `cdk diff` when a template contains non-English languages or emoji. We can detect this case and consider these strings equal.

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

Many AWS services accept non-ASCII input, eg many "description" fields. CloudFormation will correctly dispatch these templates but when invoking `GetStackTemplate` the result is mangled. This causes annoying noise in the output of `cdk diff`:

```
Resources
[~] AWS::Lambda::Function Lambda/Resource
 └─ [~] Description
     ├─ [-] ?????
     └─ [+] 🤦🏻‍♂️
```

This change modifies the diff algorithm to consider the string equal if the lvalue is a mangled version of the rvalue.

Of course this runs the risk of hiding changesets which modify only a single non-ASCII character to another non-ASCII character, but these fields already tend to be informative in nature.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked Work is blocked on this issue for this codebase. Other labels or comments may indicate why. bug This issue is a bug. effort/medium Medium work item – several days of effort needs-cfn This issue is waiting on changes to CloudFormation before it can be addressed. p1 package/tools Related to AWS CDK Tools or CLI
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants