Skip to content

feat: retain config #343

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

Merged
merged 2 commits into from
Jun 18, 2020
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
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This is the Serverless Framework plugin for AWS Step Functions.
- [Adding a custom name for a state machine](#adding-a-custom-name-for-a-statemachine)
- [Adding a custom logical id for a stateMachine](#adding-a-custom-logical-id-for-a-statemachine)
- [Depending on another logical id](#depending-on-another-logical-id)
- [Adding retain property for a state machine](#adding-retain-property-for-a-statemachine)
- [CloudWatch Alarms](#cloudwatch-alarms)
- [CloudWatch Notifications](#cloudwatch-notifications)
- [Blue-Green deployments](#blue-green-deployment)
Expand Down Expand Up @@ -219,6 +220,17 @@ stepFunctions:
- myOtherDB
- myStream
```
### Adding retain property for a stateMachine
There are some practical cases when you would like to prevent state machine from deletion on stack delete or update. This can be achieved by adding `retain` property to the state machine section.

```yaml
stepFunctions:
stateMachines:
myStateMachine:
retain: true
```

Configuring in such way adds `"DeletionPolicy" : "Retain"` to the state machine within CloudFormation template.

### CloudWatch Alarms

Expand Down
4 changes: 4 additions & 0 deletions lib/deploy/stepFunctions/compileStateMachines.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ module.exports = {
[stateMachineLogicalId]: stateMachineTemplate,
};

if (stateMachineObj.retain) {
newStateMachineObject[stateMachineLogicalId].DeletionPolicy = 'Retain';
}

if (stateMachineObj.name) {
newStateMachineObject[
stateMachineLogicalId].Properties.StateMachineName = stateMachineObj.name;
Expand Down
2 changes: 2 additions & 0 deletions lib/deploy/stepFunctions/compileStateMachines.schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const alarms = Joi.object();
const notifications = Joi.object();
const useExactVersion = Joi.boolean().default(false);
const type = Joi.string().valid('STANDARD', 'EXPRESS').default('STANDARD');
const retain = Joi.boolean().default(false);

const schema = Joi.object().keys({
id,
Expand All @@ -55,6 +56,7 @@ const schema = Joi.object().keys({
alarms,
notifications,
type,
retain,
loggingConfig,
inheritGlobalTags,
});
Expand Down
18 changes: 18 additions & 0 deletions lib/deploy/stepFunctions/compileStateMachines.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1430,4 +1430,22 @@ describe('#compileStateMachines', () => {
expect(Object.keys(serverlessStepFunctions.serverless.service.provider
.compiledCloudFormationTemplate.Outputs).length).to.equal(0);
});

it('should add DeletionPolicy when retain is true', () => {
serverless.service.stepFunctions = {
stateMachines: {
myStateMachine1: {
definition: 'definition1',
name: 'stateMachineBeta1',
retain: true,
},
},
};

serverlessStepFunctions.compileStateMachines();

expect(serverlessStepFunctions.serverless.service
.provider.compiledCloudFormationTemplate.Resources
.StateMachineBeta1.DeletionPolicy).to.equal('Retain');
});
});