Skip to content

Commit f49c33b

Browse files
authored
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
1 parent 561cffb commit f49c33b

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

Diff for: packages/@aws-cdk/cdk/lib/cloudformation/resource.ts

+7
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ export class Resource extends Referenceable {
191191
DependsOn: ignoreEmpty(this, this.renderDependsOn()),
192192
CreationPolicy: capitalizePropertyNames(this, this.options.creationPolicy),
193193
UpdatePolicy: capitalizePropertyNames(this, this.options.updatePolicy),
194+
UpdateReplacePolicy: capitalizePropertyNames(this, this.options.updateReplacePolicy),
194195
DeletionPolicy: capitalizePropertyNames(this, this.options.deletionPolicy),
195196
Metadata: ignoreEmpty(this, this.options.metadata),
196197
Condition: this.options.condition && this.options.condition.logicalId
@@ -270,6 +271,12 @@ export interface ResourceOptions {
270271
*/
271272
updatePolicy?: UpdatePolicy;
272273

274+
/**
275+
* Use the UpdateReplacePolicy attribute to retain or (in some cases) backup the existing physical instance of a resource
276+
* when it is replaced during a stack update operation.
277+
*/
278+
updateReplacePolicy?: DeletionPolicy;
279+
273280
/**
274281
* Metadata associated with the CloudFormation resource. This is not the same as the construct metadata which can be added
275282
* using construct.addMetadata(), but would not appear in the CloudFormation template automatically.

Diff for: packages/@aws-cdk/cdk/test/cloudformation/test.resource.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ export = {
165165
test.done();
166166
},
167167

168-
'creation/update/deletion policies can be set on a resource'(test: Test) {
168+
'creation/update/updateReplace/deletion policies can be set on a resource'(test: Test) {
169169
const stack = new Stack();
170170
const r1 = new Resource(stack, 'Resource', { type: 'Type' });
171171

@@ -181,6 +181,7 @@ export = {
181181
},
182182
};
183183
r1.options.deletionPolicy = DeletionPolicy.Retain;
184+
r1.options.updateReplacePolicy = DeletionPolicy.Snapshot;
184185

185186
test.deepEqual(stack.toCloudFormation(), {
186187
Resources: {
@@ -196,7 +197,8 @@ export = {
196197
BeforeAllowTrafficHook: 'lambda1',
197198
},
198199
},
199-
DeletionPolicy: 'Retain'
200+
DeletionPolicy: 'Retain',
201+
UpdateReplacePolicy: 'Snapshot'
200202
}
201203
}
202204
});

0 commit comments

Comments
 (0)