Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cdk): Support UpdateReplacePolicy on Resources #1610

Merged
merged 1 commit into from
Jan 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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