Skip to content

Commit e5dab7c

Browse files
authored
fix(cfn-include): allow boolean values for string-typed properties (#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*
1 parent 3f1c02d commit e5dab7c

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"Resources": {
3+
"Bucket": {
4+
"Type": "AWS::S3::Bucket",
5+
"Properties": {
6+
"AccessControl": true
7+
}
8+
}
9+
}
10+
}

packages/@aws-cdk/cloudformation-include/test/valid-templates.test.ts

+8
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,14 @@ describe('CDK Include', () => {
116116
);
117117
});
118118

119+
test('accepts booleans for properties with type string', () => {
120+
includeTestTemplate(stack, 'boolean-for-string.json');
121+
122+
expect(stack).toMatchTemplate(
123+
loadTestFileToJsObject('boolean-for-string.json'),
124+
);
125+
});
126+
119127
test('correctly changes the logical IDs, including references, if imported with preserveLogicalIds=false', () => {
120128
const cfnTemplate = includeTestTemplate(stack, 'bucket-with-encryption-key.json', {
121129
preserveLogicalIds: false,

packages/@aws-cdk/core/lib/cfn-parse.ts

+6
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@ export class FromCloudFormation {
132132
return new FromCloudFormationResult(value.toString());
133133
}
134134

135+
// CloudFormation treats booleans and strings interchangeably;
136+
// so, if we get a boolean here, convert it to a string
137+
if (typeof value === 'boolean') {
138+
return new FromCloudFormationResult(value.toString());
139+
}
140+
135141
// in all other cases, just return the input,
136142
// and let a validator handle it if it's not a string
137143
return new FromCloudFormationResult(value);

0 commit comments

Comments
 (0)