diff --git a/packages/@aws-cdk/cloudformation-include/test/test-templates/boolean-for-string.json b/packages/@aws-cdk/cloudformation-include/test/test-templates/boolean-for-string.json new file mode 100644 index 0000000000000..1ef8d59e40b89 --- /dev/null +++ b/packages/@aws-cdk/cloudformation-include/test/test-templates/boolean-for-string.json @@ -0,0 +1,10 @@ +{ + "Resources": { + "Bucket": { + "Type": "AWS::S3::Bucket", + "Properties": { + "AccessControl": true + } + } + } +} diff --git a/packages/@aws-cdk/cloudformation-include/test/valid-templates.test.ts b/packages/@aws-cdk/cloudformation-include/test/valid-templates.test.ts index 34b403a2e7a99..3d8b51098d293 100644 --- a/packages/@aws-cdk/cloudformation-include/test/valid-templates.test.ts +++ b/packages/@aws-cdk/cloudformation-include/test/valid-templates.test.ts @@ -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, diff --git a/packages/@aws-cdk/core/lib/cfn-parse.ts b/packages/@aws-cdk/core/lib/cfn-parse.ts index 93376ae19d365..8f5d820584d98 100644 --- a/packages/@aws-cdk/core/lib/cfn-parse.ts +++ b/packages/@aws-cdk/core/lib/cfn-parse.ts @@ -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);