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

cfn_tools.dump_yaml strips quotes, causing loaded YAML template invalid #78

Closed
canhnt opened this issue May 28, 2019 · 8 comments
Closed

Comments

@canhnt
Copy link

canhnt commented May 28, 2019

Description

When parsing YAML files containing string scalar longer than 8 chars and start with 0, the function cfn_tools.dump_yaml strips single (and double) quotes, which converts string scalar to number scalar. When CFN templates refers these string values in Ref or Sub functions, it causes template error.

Package version: 1.2.0

$ pip show cfn_flip
Name: cfn-flip
Version: 1.2.0
Summary: Convert AWS CloudFormation templates between JSON and YAML formats
Home-page: https://github.com/awslabs/aws-cfn-template-flip
Author: Steve Engledow
Author-email: [email protected]
License: Apache2
Location: /usr/local/lib/python2.7/site-packages
Requires: six, PyYAML, Click
Required-by:

Test-cases

1. Test case '012345678'

import cfn_tools
content = "Parameters:\n  MyAccountId:\n    Type: String\n    Default: '012345678'"
body = cfn_tools.load_yaml(content)
template_body = cfn_tools.dump_yaml(body)
print template_body

Expected output:

Parameters:
  MyAccountId:
    Type: String
    Default: '012345678'

Actual output:

Parameters:
  MyAccountId:
    Type: String
    Default: 012345678

2. Test-case '01234567'

import cfn_tools
content = "Parameters:\n  MyAccountId:\n    Type: String\n    Default: '01234567'"
body = cfn_tools.load_yaml(content)
template_body = cfn_tools.dump_yaml(body)
print template_body

Output:

Parameters:
  MyAccountId:
    Type: String
    Default: '01234567'
@canhnt
Copy link
Author

canhnt commented May 28, 2019

Workaround solution:

import cfn_tools
import cfn_flip

content = "Parameters:\n  MyAccountId:\n    Type: String\n    Default: '012345678'"
body = cfn_tools.load_yaml(content)
template_body_json = cfn_tools.dump_json(body)
template_body_yaml = cfn_flip.to_yaml(template_body_json)
print template_body_yaml

Output

Parameters:
  MyAccountId:
    Type: String
    Default: '012345678'

@koiker
Copy link
Collaborator

koiker commented May 28, 2019

This is related with the pyYaml and this: yaml/pyyaml#98

But I will work in a workaround to deal with AWS AccountId in the conversion. :-)

@koiker
Copy link
Collaborator

koiker commented May 28, 2019

The PR: #79 should fix the issue.

@koiker koiker closed this as completed May 28, 2019
@canhnt
Copy link
Author

canhnt commented May 28, 2019

Thank you for your fix. I think it would be nice when PR is merged to master, we can close the issue. Otherwise the bug is still valid in the the latest branch (master).

@koiker koiker reopened this May 28, 2019
@koiker
Copy link
Collaborator

koiker commented May 28, 2019

Sure, I've closed too early :-)

@stilvoid
Copy link
Member

stilvoid commented Jun 4, 2019

Fixed in #79 :)

@stilvoid stilvoid closed this as completed Jun 4, 2019
@canhnt
Copy link
Author

canhnt commented Jun 4, 2019

Thanks. It'll be released in the next tag, i.e. after v1.2.0

@stilvoid
Copy link
Member

stilvoid commented Jun 4, 2019

Yes. After the next PR is merged, I'll be releasing as v1.2.1. Hopefully today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants