Skip to content

Commit

Permalink
feat(cdk): Support UpdateReplacePolicy on Resources (#1610)
Browse files Browse the repository at this point in the history
Support the new UpdateReplacePolicy option of the CloudFormation
resources.

See: https://docs.aws.amazon.com/fr_fr/AWSCloudFormation/latest/UserGuide/aws-attribute-updatereplacepolicy.html
  • Loading branch information
RomainMuller committed Jan 28, 2019
1 parent 561cffb commit f49c33b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 7 additions & 0 deletions packages/@aws-cdk/cdk/lib/cloudformation/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 4 additions & 2 deletions packages/@aws-cdk/cdk/test/cloudformation/test.resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' });

Expand All @@ -181,6 +181,7 @@ export = {
},
};
r1.options.deletionPolicy = DeletionPolicy.Retain;
r1.options.updateReplacePolicy = DeletionPolicy.Snapshot;

test.deepEqual(stack.toCloudFormation(), {
Resources: {
Expand All @@ -196,7 +197,8 @@ export = {
BeforeAllowTrafficHook: 'lambda1',
},
},
DeletionPolicy: 'Retain'
DeletionPolicy: 'Retain',
UpdateReplacePolicy: 'Snapshot'
}
}
});
Expand Down

0 comments on commit f49c33b

Please sign in to comment.