From 46d3b08ae5d17868eea8cb2cffedd9addbb6d1e7 Mon Sep 17 00:00:00 2001 From: Adam Ruka Date: Thu, 24 Sep 2020 18:02:42 -0700 Subject: [PATCH 1/3] feat: support the 'Description' resource attribute One more resource attribute that we missed, and that is needed for cfn-include to be able to handle ingesting all templates. --- .../cloudformation-include/lib/cfn-include.ts | 2 +- .../custom-resource-with-attributes.json | 1 + packages/@aws-cdk/core/lib/cfn-parse.ts | 1 + packages/@aws-cdk/core/lib/cfn-resource.ts | 11 +++++++++++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/@aws-cdk/cloudformation-include/lib/cfn-include.ts b/packages/@aws-cdk/cloudformation-include/lib/cfn-include.ts index aad5c653c3693..ab79cfa4d3343 100644 --- a/packages/@aws-cdk/cloudformation-include/lib/cfn-include.ts +++ b/packages/@aws-cdk/cloudformation-include/lib/cfn-include.ts @@ -589,7 +589,7 @@ export class CfnInclude extends core.CfnElement { // fail early for resource attributes we don't support yet const knownAttributes = [ - 'Type', 'Properties', 'Condition', 'DependsOn', 'Metadata', 'Version', + 'Type', 'Properties', 'Condition', 'DependsOn', 'Metadata', 'Version', 'Description', 'CreationPolicy', 'UpdatePolicy', 'DeletionPolicy', 'UpdateReplacePolicy', ]; for (const attribute of Object.keys(resourceAttributes)) { 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 c490a16515944..b1dcf4d219bf1 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 @@ -28,6 +28,7 @@ }, "CustomResource": { "Type": "AWS::CloudFormation::CustomResource", + "Description": "some random custom resource", "Properties": { "ServiceToken": "CustomValue", "CustomFuncProp": { diff --git a/packages/@aws-cdk/core/lib/cfn-parse.ts b/packages/@aws-cdk/core/lib/cfn-parse.ts index 7a18378556b9d..e10789c23d496 100644 --- a/packages/@aws-cdk/core/lib/cfn-parse.ts +++ b/packages/@aws-cdk/core/lib/cfn-parse.ts @@ -285,6 +285,7 @@ export class CfnParser { cfnOptions.deletionPolicy = this.parseDeletionPolicy(resourceAttributes.DeletionPolicy); cfnOptions.updateReplacePolicy = this.parseDeletionPolicy(resourceAttributes.UpdateReplacePolicy); cfnOptions.version = this.parseValue(resourceAttributes.Version); + cfnOptions.description = this.parseValue(resourceAttributes.Description); cfnOptions.metadata = this.parseValue(resourceAttributes.Metadata); // handle Condition diff --git a/packages/@aws-cdk/core/lib/cfn-resource.ts b/packages/@aws-cdk/core/lib/cfn-resource.ts index fcb1c95eaf5bb..c5bc4e053250d 100644 --- a/packages/@aws-cdk/core/lib/cfn-resource.ts +++ b/packages/@aws-cdk/core/lib/cfn-resource.ts @@ -301,6 +301,7 @@ export class CfnResource extends CfnRefElement { UpdateReplacePolicy: capitalizePropertyNames(this, this.cfnOptions.updateReplacePolicy), DeletionPolicy: capitalizePropertyNames(this, this.cfnOptions.deletionPolicy), Version: this.cfnOptions.version, + Description: this.cfnOptions.description, Metadata: ignoreEmpty(this.cfnOptions.metadata), Condition: this.cfnOptions.condition && this.cfnOptions.condition.logicalId, }, props => { @@ -438,6 +439,16 @@ export interface ICfnResourceOptions { */ version?: string; + /** + * The description of this resource. + * Used for informational purposes only, + * is not processed in any way + * (and stays with the CloudFormation template, + * is not passed to the udnerlying resource, + * even if it does have a 'description' property). + */ + description?: string; + /** * Metadata associated with the CloudFormation resource. This is not the same as the construct metadata which can be added * using construct.addMetadata(), but would not appear in the CloudFormation template automatically. From 901eff4c80a2b061b3c4547211ecc63afcaa52c3 Mon Sep 17 00:00:00 2001 From: Adam Ruka Date: Fri, 25 Sep 2020 16:47:40 -0700 Subject: [PATCH 2/3] Apply Shiv's suggestions from the code review --- packages/@aws-cdk/cloudformation-include/lib/cfn-include.ts | 4 ++-- packages/@aws-cdk/core/lib/cfn-resource.ts | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/@aws-cdk/cloudformation-include/lib/cfn-include.ts b/packages/@aws-cdk/cloudformation-include/lib/cfn-include.ts index ab79cfa4d3343..55c450a453a2b 100644 --- a/packages/@aws-cdk/cloudformation-include/lib/cfn-include.ts +++ b/packages/@aws-cdk/cloudformation-include/lib/cfn-include.ts @@ -589,8 +589,8 @@ export class CfnInclude extends core.CfnElement { // fail early for resource attributes we don't support yet const knownAttributes = [ - 'Type', 'Properties', 'Condition', 'DependsOn', 'Metadata', 'Version', 'Description', - 'CreationPolicy', 'UpdatePolicy', 'DeletionPolicy', 'UpdateReplacePolicy', + 'Condition', 'DependsOn', 'Description', 'Metadata', 'Properties', 'Type', 'Version', + 'CreationPolicy', 'DeletionPolicy', 'UpdatePolicy', 'UpdateReplacePolicy' ]; for (const attribute of Object.keys(resourceAttributes)) { if (!knownAttributes.includes(attribute)) { diff --git a/packages/@aws-cdk/core/lib/cfn-resource.ts b/packages/@aws-cdk/core/lib/cfn-resource.ts index c5bc4e053250d..f5049bdcd2326 100644 --- a/packages/@aws-cdk/core/lib/cfn-resource.ts +++ b/packages/@aws-cdk/core/lib/cfn-resource.ts @@ -441,10 +441,8 @@ export interface ICfnResourceOptions { /** * The description of this resource. - * Used for informational purposes only, - * is not processed in any way - * (and stays with the CloudFormation template, - * is not passed to the udnerlying resource, + * Used for informational purposes only, is not processed in any way + * (and stays with the CloudFormation template, is not passed to the underlying resource, * even if it does have a 'description' property). */ description?: string; From 3fa5e58e6a369a383483daa7bb43811a611513d3 Mon Sep 17 00:00:00 2001 From: Adam Ruka Date: Fri, 25 Sep 2020 16:48:51 -0700 Subject: [PATCH 3/3] Missed a trailing comma --- packages/@aws-cdk/cloudformation-include/lib/cfn-include.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/cloudformation-include/lib/cfn-include.ts b/packages/@aws-cdk/cloudformation-include/lib/cfn-include.ts index 55c450a453a2b..becb5666c3653 100644 --- a/packages/@aws-cdk/cloudformation-include/lib/cfn-include.ts +++ b/packages/@aws-cdk/cloudformation-include/lib/cfn-include.ts @@ -590,7 +590,7 @@ export class CfnInclude extends core.CfnElement { // fail early for resource attributes we don't support yet const knownAttributes = [ 'Condition', 'DependsOn', 'Description', 'Metadata', 'Properties', 'Type', 'Version', - 'CreationPolicy', 'DeletionPolicy', 'UpdatePolicy', 'UpdateReplacePolicy' + 'CreationPolicy', 'DeletionPolicy', 'UpdatePolicy', 'UpdateReplacePolicy', ]; for (const attribute of Object.keys(resourceAttributes)) { if (!knownAttributes.includes(attribute)) {