Skip to content

Commit 627a87a

Browse files
- make tags an object instead of Array and provide better syntax for the plugin
1 parent 2fff9c0 commit 627a87a

File tree

3 files changed

+20
-30
lines changed

3 files changed

+20
-30
lines changed

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ stepFunctions:
4949
End: true
5050
dependsOn: CustomIamRole
5151
tags:
52-
- Key: Team
53-
Value: Atlantis
52+
Team: Atlantis
5453
alarms:
5554
topics:
5655
ok: arn:aws:sns:us-east-1:1234567890:NotifyMe
@@ -76,8 +75,7 @@ stepFunctions:
7675
- KinesisStream
7776
- CUstomIamRole
7877
tags:
79-
- Key: Team
80-
Value: Atlantis
78+
Team: Atlantis
8179
activities:
8280
- myTask
8381
- yourTask

lib/deploy/stepFunctions/compileStateMachines.js

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

2121
if (stateMachineObj.definition) {
2222
if (typeof stateMachineObj.definition === 'string') {
@@ -84,17 +84,15 @@ module.exports = {
8484
}
8585
}
8686

87-
if (_.isArray(stateMachineObj.tags)) {
88-
const malformedTags =
89-
stateMachineObj.tags.filter(x => !_.isString(x.Key) || !_.isString(x.Value));
90-
if (!_.isEmpty(malformedTags)) {
91-
const errorMsg = `${malformedTags.length} tags are malformed. ` +
92-
'Expect tags to have shape {Key:string, Value: String}';
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 {
9393
throw new this.serverless.classes
94-
.Error(errorMsg);
94+
.Error('Unable to parse tags, it should be an object.');
9595
}
96-
97-
Tags = stateMachineObj.tags;
9896
}
9997

10098
const stateMachineLogicalId = this.getStateMachineLogicalId(stateMachineName,

lib/deploy/stepFunctions/compileStateMachines.test.js

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -490,24 +490,18 @@ describe('#compileStateMachines', () => {
490490
myStateMachine1: {
491491
definition: 'definition1',
492492
name: 'stateMachineBeta1',
493-
tags: [{
494-
Key: 'team',
495-
Value: 'core',
496-
}, {
497-
Key: 'feature',
498-
Value: 'tags',
499-
}],
493+
tags: {
494+
team: 'core',
495+
score: 42,
496+
},
500497
},
501498
myStateMachine2: {
502499
definition: 'definition2',
503500
name: 'stateMachineBeta2',
504-
tags: [{
505-
Key: 'team',
506-
Value: 'core',
507-
}, {
508-
Key: 'feature',
509-
Value: 'tags',
510-
}],
501+
tags: {
502+
team: 'core',
503+
score: 42,
504+
},
511505
},
512506
},
513507
};
@@ -522,9 +516,9 @@ describe('#compileStateMachines', () => {
522516
expect(stateMachineBeta1.Properties.Tags).to.have.lengthOf(2);
523517
expect(stateMachineBeta2.Properties.Tags).to.have.lengthOf(2);
524518
expect(stateMachineBeta1.Properties.Tags)
525-
.to.deep.eq([{ Key: 'team', Value: 'core' }, { Key: 'feature', Value: 'tags' }]);
519+
.to.deep.eq([{ Key: 'team', Value: 'core' }, { Key: 'score', Value: '42' }]);
526520
expect(stateMachineBeta2.Properties.Tags)
527-
.to.deep.eq([{ Key: 'team', Value: 'core' }, { Key: 'feature', Value: 'tags' }]);
521+
.to.deep.eq([{ Key: 'team', Value: 'core' }, { Key: 'score', Value: '42' }]);
528522
});
529523

530524
it('should throw error when tags property contains malformed tags', () => {

0 commit comments

Comments
 (0)