Skip to content

Commit 460643a

Browse files
committed
feat: retain config
add ability to set DeletionPolicy to Retain for State Machine
1 parent 24ed301 commit 460643a

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

lib/deploy/stepFunctions/compileStateMachines.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,10 @@ module.exports = {
224224
[stateMachineLogicalId]: stateMachineTemplate,
225225
};
226226

227+
if (stateMachineObj.retain) {
228+
newStateMachineObject[stateMachineLogicalId].DeletionPolicy = 'Retain';
229+
}
230+
227231
if (stateMachineObj.name) {
228232
newStateMachineObject[
229233
stateMachineLogicalId].Properties.StateMachineName = stateMachineObj.name;

lib/deploy/stepFunctions/compileStateMachines.schema.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const alarms = Joi.object();
4242
const notifications = Joi.object();
4343
const useExactVersion = Joi.boolean().default(false);
4444
const type = Joi.string().valid('STANDARD', 'EXPRESS').default('STANDARD');
45+
const retain = Joi.boolean().default(false);
4546

4647
const schema = Joi.object().keys({
4748
id,
@@ -55,6 +56,7 @@ const schema = Joi.object().keys({
5556
alarms,
5657
notifications,
5758
type,
59+
retain,
5860
loggingConfig,
5961
inheritGlobalTags,
6062
});

lib/deploy/stepFunctions/compileStateMachines.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,4 +1430,22 @@ describe('#compileStateMachines', () => {
14301430
expect(Object.keys(serverlessStepFunctions.serverless.service.provider
14311431
.compiledCloudFormationTemplate.Outputs).length).to.equal(0);
14321432
});
1433+
1434+
it('should add DeletionPolicy when retain is true', () => {
1435+
serverless.service.stepFunctions = {
1436+
stateMachines: {
1437+
myStateMachine1: {
1438+
definition: 'definition1',
1439+
name: 'stateMachineBeta1',
1440+
retain: true,
1441+
},
1442+
},
1443+
};
1444+
1445+
serverlessStepFunctions.compileStateMachines();
1446+
1447+
expect(serverlessStepFunctions.serverless.service
1448+
.provider.compiledCloudFormationTemplate.Resources
1449+
.StateMachineBeta1.DeletionPolicy).to.equal('Retain');
1450+
});
14331451
});

0 commit comments

Comments
 (0)