Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Failure with utf-8 characters on Windows #183

Closed
cmbrad opened this issue Nov 15, 2019 · 4 comments
Closed

Failure with utf-8 characters on Windows #183

cmbrad opened this issue Nov 15, 2019 · 4 comments
Assignees
Labels
bug waiting for confirmation Workaround/Fix applied, waiting for confirmation

Comments

@cmbrad
Copy link

cmbrad commented Nov 15, 2019

Description :

On windows the default system encoding is cp1252

>> locale.getpreferredencoding()
'cp1252'

as opposed to my RHEL system where:

>> locale.getpreferredencoding()
'UTF-8'

When a plan contains UTF-8 characters, perhaps in a description field for a variable, this causes an error on Windows of the form: 'charmap' codec can't decode byte 0x9d in position 99999: character maps to <undefined>.

To Reproduce

  1. Have a variable with a utf-8 specific character such
variable "my_var" {
  description = "My weird characters: “Java” or “Windows”"
  default     = null
}
  1. terraform-compliance -p plan.out -f rules
  2. Running using python package
ERROR: C:\Users\...\plan.out.json is not a valid JSON file.

       Did you try to convert the binary plan file to json with "terraform show -json C:\Users\...\plan.out.json > C:\Users\...\plan.out.json.json" ?

Expected behavior :

It doesn't crash with an error!

Tested versions :

  • terraform-compliance version v1.0.56
  • terraform version v0.12.15
  • python version 3.7.3

Additional context

Adding 'encoding="utf8"' to the various open calls fixes it - ie open(values, 'r', encoding='utf8') although not sure what impact this has on other versions of Python. For now the workaround is to only run this in CI & stop people adding utf8 characters to modules.

@eerkunt
Copy link
Member

eerkunt commented Nov 15, 2019

Trying to reproduce the problem, once reproduced will fix it permanently.

Meanwhile, did you try to run terraform-compliance after you set PYTHONIOENCODING environment varialbe to UTF-8 ?

eerkunt added a commit that referenced this issue Nov 15, 2019
@eerkunt
Copy link
Member

eerkunt commented Nov 15, 2019

This is a very good finding 🎉 Thanks @cmbrad !

It looks like PYTHONIOENCODING doesn't solve this problem. Will release 1.0.57 after CI checks pass.

@eerkunt
Copy link
Member

eerkunt commented Nov 15, 2019

Please have a try with 1.0.57 and let me know if this is still not working for you ?

Thanks!

@eerkunt eerkunt added the waiting for confirmation Workaround/Fix applied, waiting for confirmation label Nov 15, 2019
@eerkunt
Copy link
Member

eerkunt commented Dec 28, 2019

Closing the issue due to inactivity. Please do not hesitate to open a new issue if the problem still continue.

Thanks 🎉

@eerkunt eerkunt closed this as completed Dec 28, 2019
@terraform-compliance terraform-compliance locked as resolved and limited conversation to collaborators Dec 28, 2019
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
bug waiting for confirmation Workaround/Fix applied, waiting for confirmation
Projects
None yet
Development

No branches or pull requests

2 participants