From 1a5a024b601e28d158b6401b5d97ed408a73eb5d Mon Sep 17 00:00:00 2001 From: Adam Ruka Date: Mon, 21 Sep 2020 04:17:47 -0700 Subject: [PATCH] fix(cfn-include): correctly handle the 'AWS::CloudFormation::CustomResource' resource type (#10415) The resource type 'AWS::CloudFormation::CustomResource' corresponds to the class CfnCustomResource. However, that class is automatically generated, and quite useless; it only supports one property, ServiceToken. It does not support passing in an arbitrary collection of properties, like custom resources in CloudFormation do. As a result, cfn-include would "lose" all properties of resources of type 'AWS::CloudFormation::CustomResource' other than ServiceToken. Fix the problem by handling this resource type with the CfnResource class, that does support an arbitrary collection of properties. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- packages/@aws-cdk/cloudformation-include/lib/cfn-include.ts | 6 +++++- .../test-templates/custom-resource-with-attributes.json | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/@aws-cdk/cloudformation-include/lib/cfn-include.ts b/packages/@aws-cdk/cloudformation-include/lib/cfn-include.ts index c19361247bf09..aad5c653c3693 100644 --- a/packages/@aws-cdk/cloudformation-include/lib/cfn-include.ts +++ b/packages/@aws-cdk/cloudformation-include/lib/cfn-include.ts @@ -634,7 +634,11 @@ export class CfnInclude extends core.CfnElement { l1Instance = this.createNestedStack(logicalId, cfnParser); } else { const l1ClassFqn = cfn_type_to_l1_mapping.lookup(resourceAttributes.Type); - if (l1ClassFqn) { + // The AWS::CloudFormation::CustomResource type corresponds to the CfnCustomResource class. + // Unfortunately, it's quite useless; it only has a single property, ServiceToken. + // For that reason, even the CustomResource class from @core doesn't use it! + // So, special-case the handling of this one resource type + if (l1ClassFqn && resourceAttributes.Type !== 'AWS::CloudFormation::CustomResource') { const options: cfn_parse.FromCloudFormationOptions = { parser: cfnParser, }; diff --git a/packages/@aws-cdk/cloudformation-include/test/test-templates/custom-resource-with-attributes.json b/packages/@aws-cdk/cloudformation-include/test/test-templates/custom-resource-with-attributes.json index 716224153dbb9..c490a16515944 100644 --- a/packages/@aws-cdk/cloudformation-include/test/test-templates/custom-resource-with-attributes.json +++ b/packages/@aws-cdk/cloudformation-include/test/test-templates/custom-resource-with-attributes.json @@ -27,9 +27,9 @@ "DependsOn": [ "CustomResource" ] }, "CustomResource": { - "Type": "AWS::MyService::AnotherCustom", + "Type": "AWS::CloudFormation::CustomResource", "Properties": { - "CustomProp": "CustomValue", + "ServiceToken": "CustomValue", "CustomFuncProp": { "Ref": "AWS::NoValue" }