From f49c33b7c8cb35fe43c806e099c692cbad5f7b7c Mon Sep 17 00:00:00 2001 From: Romain Marcadier-Muller Date: Mon, 28 Jan 2019 11:09:22 +0100 Subject: [PATCH] feat(cdk): Support UpdateReplacePolicy on Resources (#1610) Support the new UpdateReplacePolicy option of the CloudFormation resources. See: https://docs.aws.amazon.com/fr_fr/AWSCloudFormation/latest/UserGuide/aws-attribute-updatereplacepolicy.html --- packages/@aws-cdk/cdk/lib/cloudformation/resource.ts | 7 +++++++ packages/@aws-cdk/cdk/test/cloudformation/test.resource.ts | 6 ++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/@aws-cdk/cdk/lib/cloudformation/resource.ts b/packages/@aws-cdk/cdk/lib/cloudformation/resource.ts index a2a4243dde2ac..75b5a26f9e371 100644 --- a/packages/@aws-cdk/cdk/lib/cloudformation/resource.ts +++ b/packages/@aws-cdk/cdk/lib/cloudformation/resource.ts @@ -191,6 +191,7 @@ export class Resource extends Referenceable { DependsOn: ignoreEmpty(this, this.renderDependsOn()), CreationPolicy: capitalizePropertyNames(this, this.options.creationPolicy), UpdatePolicy: capitalizePropertyNames(this, this.options.updatePolicy), + UpdateReplacePolicy: capitalizePropertyNames(this, this.options.updateReplacePolicy), DeletionPolicy: capitalizePropertyNames(this, this.options.deletionPolicy), Metadata: ignoreEmpty(this, this.options.metadata), Condition: this.options.condition && this.options.condition.logicalId @@ -270,6 +271,12 @@ export interface ResourceOptions { */ updatePolicy?: UpdatePolicy; + /** + * Use the UpdateReplacePolicy attribute to retain or (in some cases) backup the existing physical instance of a resource + * when it is replaced during a stack update operation. + */ + updateReplacePolicy?: DeletionPolicy; + /** * 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. diff --git a/packages/@aws-cdk/cdk/test/cloudformation/test.resource.ts b/packages/@aws-cdk/cdk/test/cloudformation/test.resource.ts index 3b0ee595aa35a..532b498512d42 100644 --- a/packages/@aws-cdk/cdk/test/cloudformation/test.resource.ts +++ b/packages/@aws-cdk/cdk/test/cloudformation/test.resource.ts @@ -165,7 +165,7 @@ export = { test.done(); }, - 'creation/update/deletion policies can be set on a resource'(test: Test) { + 'creation/update/updateReplace/deletion policies can be set on a resource'(test: Test) { const stack = new Stack(); const r1 = new Resource(stack, 'Resource', { type: 'Type' }); @@ -181,6 +181,7 @@ export = { }, }; r1.options.deletionPolicy = DeletionPolicy.Retain; + r1.options.updateReplacePolicy = DeletionPolicy.Snapshot; test.deepEqual(stack.toCloudFormation(), { Resources: { @@ -196,7 +197,8 @@ export = { BeforeAllowTrafficHook: 'lambda1', }, }, - DeletionPolicy: 'Retain' + DeletionPolicy: 'Retain', + UpdateReplacePolicy: 'Snapshot' } } });