Skip to content

Commit

Permalink
fix(cfn-include): allow boolean values for string-typed properties (#…
Browse files Browse the repository at this point in the history
…13508)

CloudFormation is pretty lax when it comes to the types it accepts,
and allows passing a boolean where a string is expected.
Allow that possibility in cloudformation-include.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
skinny85 authored Mar 10, 2021
1 parent 3f1c02d commit e5dab7c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"Resources": {
"Bucket": {
"Type": "AWS::S3::Bucket",
"Properties": {
"AccessControl": true
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ describe('CDK Include', () => {
);
});

test('accepts booleans for properties with type string', () => {
includeTestTemplate(stack, 'boolean-for-string.json');

expect(stack).toMatchTemplate(
loadTestFileToJsObject('boolean-for-string.json'),
);
});

test('correctly changes the logical IDs, including references, if imported with preserveLogicalIds=false', () => {
const cfnTemplate = includeTestTemplate(stack, 'bucket-with-encryption-key.json', {
preserveLogicalIds: false,
Expand Down
6 changes: 6 additions & 0 deletions packages/@aws-cdk/core/lib/cfn-parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ export class FromCloudFormation {
return new FromCloudFormationResult(value.toString());
}

// CloudFormation treats booleans and strings interchangeably;
// so, if we get a boolean here, convert it to a string
if (typeof value === 'boolean') {
return new FromCloudFormationResult(value.toString());
}

// in all other cases, just return the input,
// and let a validator handle it if it's not a string
return new FromCloudFormationResult(value);
Expand Down

0 comments on commit e5dab7c

Please sign in to comment.