Skip to content

Commit

Permalink
fix(yaml-cfn): do not deserialize year-month-date as strings
Browse files Browse the repository at this point in the history
Currently, we are using the `yaml-1.1` schema when de-serializing YAML documents,
Unfortunately, this has the side effect of treating unquoted parts of the template like '2010-09-09'
as Date objects, instead of just simple strings.
This has been noted by a customer using the cloudformation-include module,
but I assume a very similar problem exists for other places we parse YAML,
like cloudformation-diff.

Switch to the `core` schema from `yaml-1.1`,
where those are treated as strings, instead of dates.

Fixes #13709
  • Loading branch information
skinny85 committed Mar 22, 2021
1 parent 5d62331 commit 0cdb139
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
AWSTemplateFormatVersion: 2010-09-09
Resources:
Role:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- ec2.amazonaws.com
Action:
- sts:AssumeRole
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,33 @@ describe('CDK Include', () => {
);
});

test('can ingest a template with year-month-date parsed as string instead of Date', () => {
includeTestTemplate(stack, 'year-month-date-as-strings.yaml');

expect(stack).toMatchTemplate({
"AWSTemplateFormatVersion": "2010-09-09",
"Resources": {
"Role": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": ["ec2.amazonaws.com"],
},
"Action": ["sts:AssumeRole"],
},
],
},
},
},
},
});
});

test('can ingest a template with the short form Base64 function', () => {
includeTestTemplate(stack, 'short-form-base64.yaml');

Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/yaml-cfn/lib/yaml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ const shortForms: yaml_types.Schema.CustomTag[] = [
function parseYamlStrWithCfnTags(text: string): any {
return yaml.parse(text, {
customTags: shortForms,
schema: 'yaml-1.1',
schema: 'core',
});
}

0 comments on commit 0cdb139

Please sign in to comment.