Skip to content

Commit b59baed

Browse files
authored
Merge pull request #181 from theburningmonk/feature/support_tagging
Feature/support tagging
2 parents 2009cf9 + 627a87a commit b59baed

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ stepFunctions:
4848
Resource: arn:aws:lambda:#{AWS::Region}:#{AWS::AccountId}:function:${self:service}-${opt:stage}-hello
4949
End: true
5050
dependsOn: CustomIamRole
51+
tags:
52+
Team: Atlantis
5153
alarms:
5254
topics:
5355
ok: arn:aws:sns:us-east-1:1234567890:NotifyMe
@@ -72,6 +74,8 @@ stepFunctions:
7274
- DynamoDBTable
7375
- KinesisStream
7476
- CUstomIamRole
77+
tags:
78+
Team: Atlantis
7579
activities:
7680
- myTask
7781
- yourTask

lib/deploy/stepFunctions/compileStateMachines.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module.exports = {
1616
let DefinitionString;
1717
let RoleArn;
1818
let DependsOn = [];
19+
const Tags = [];
1920

2021
if (stateMachineObj.definition) {
2122
if (typeof stateMachineObj.definition === 'string') {
@@ -83,6 +84,17 @@ module.exports = {
8384
}
8485
}
8586

87+
if (stateMachineObj.tags) {
88+
if (_.isPlainObject(stateMachineObj.tags)) {
89+
_.forEach(
90+
stateMachineObj.tags,
91+
(Value, Key) => Tags.push({ Key, Value: Value.toString() }));
92+
} else {
93+
throw new this.serverless.classes
94+
.Error('Unable to parse tags, it should be an object.');
95+
}
96+
}
97+
8698
const stateMachineLogicalId = this.getStateMachineLogicalId(stateMachineName,
8799
stateMachineObj);
88100
const stateMachineOutputLogicalId = this
@@ -92,6 +104,7 @@ module.exports = {
92104
Properties: {
93105
DefinitionString,
94106
RoleArn,
107+
Tags,
95108
},
96109
DependsOn,
97110
};

lib/deploy/stepFunctions/compileStateMachines.test.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,4 +483,55 @@ describe('#compileStateMachines', () => {
483483
};
484484
expect(() => serverlessStepFunctions.compileStateMachines()).to.throw(Error);
485485
});
486+
487+
it('should add tags', () => {
488+
serverless.service.stepFunctions = {
489+
stateMachines: {
490+
myStateMachine1: {
491+
definition: 'definition1',
492+
name: 'stateMachineBeta1',
493+
tags: {
494+
team: 'core',
495+
score: 42,
496+
},
497+
},
498+
myStateMachine2: {
499+
definition: 'definition2',
500+
name: 'stateMachineBeta2',
501+
tags: {
502+
team: 'core',
503+
score: 42,
504+
},
505+
},
506+
},
507+
};
508+
509+
serverlessStepFunctions.compileStateMachines();
510+
const stateMachineBeta1 = serverlessStepFunctions.serverless.service
511+
.provider.compiledCloudFormationTemplate.Resources
512+
.StateMachineBeta1;
513+
const stateMachineBeta2 = serverlessStepFunctions.serverless.service
514+
.provider.compiledCloudFormationTemplate.Resources
515+
.StateMachineBeta2;
516+
expect(stateMachineBeta1.Properties.Tags).to.have.lengthOf(2);
517+
expect(stateMachineBeta2.Properties.Tags).to.have.lengthOf(2);
518+
expect(stateMachineBeta1.Properties.Tags)
519+
.to.deep.eq([{ Key: 'team', Value: 'core' }, { Key: 'score', Value: '42' }]);
520+
expect(stateMachineBeta2.Properties.Tags)
521+
.to.deep.eq([{ Key: 'team', Value: 'core' }, { Key: 'score', Value: '42' }]);
522+
});
523+
524+
it('should throw error when tags property contains malformed tags', () => {
525+
serverless.service.stepFunctions = {
526+
stateMachines: {
527+
myStateMachine1: {
528+
definition: 'definition1',
529+
name: 'stateMachineBeta1',
530+
tags: ['team:core'],
531+
},
532+
},
533+
};
534+
535+
expect(() => serverlessStepFunctions.compileStateMachines()).to.throw(Error);
536+
});
486537
});

0 commit comments

Comments
 (0)