Skip to content

Commit 332f0a1

Browse files
fix: exec role is no longer hardcoded
1 parent c54edd3 commit 332f0a1

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

lib/deploy/stepFunctions/compileStateMachines.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ module.exports = {
9393
if (this.isStateMachines()) {
9494
this.getAllStateMachines().forEach((stateMachineName) => {
9595
const stateMachineObj = this.getStateMachine(stateMachineName);
96+
const stateMachineLogicalId = this.getStateMachineLogicalId(stateMachineName,
97+
stateMachineObj);
9698
let DefinitionString;
9799
let RoleArn;
98100
let DependsOn = [];
@@ -158,13 +160,14 @@ module.exports = {
158160
if (stateMachineObj.role) {
159161
RoleArn = stateMachineObj.role;
160162
} else {
163+
const roleLogicalId = `${stateMachineLogicalId}Role`;
161164
RoleArn = {
162165
'Fn::GetAtt': [
163-
'IamRoleStateMachineExecution',
166+
roleLogicalId,
164167
'Arn',
165168
],
166169
};
167-
DependsOn.push('IamRoleStateMachineExecution');
170+
DependsOn.push(roleLogicalId);
168171
}
169172

170173
if (stateMachineObj.dependsOn) {
@@ -196,8 +199,7 @@ module.exports = {
196199
};
197200
}
198201

199-
const stateMachineLogicalId = this.getStateMachineLogicalId(stateMachineName,
200-
stateMachineObj);
202+
201203
const stateMachineOutputLogicalId = this
202204
.getStateMachineOutputLogicalId(stateMachineName, stateMachineObj);
203205
const stateMachineTemplate = {

lib/deploy/stepFunctions/compileStateMachines.test.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,16 @@ describe('#compileStateMachines', () => {
5555
.StateMachineBeta2.Properties.DefinitionString).to.equal('"definition2"');
5656
expect(serverlessStepFunctions.serverless.service
5757
.provider.compiledCloudFormationTemplate.Resources
58-
.StateMachineBeta1.Properties.RoleArn['Fn::GetAtt'][0]).to.equal('IamRoleStateMachineExecution');
58+
.StateMachineBeta1.Properties.RoleArn['Fn::GetAtt'][0]).to.equal('StateMachineBeta1Role');
5959
expect(serverlessStepFunctions.serverless.service
6060
.provider.compiledCloudFormationTemplate.Resources
61-
.StateMachineBeta2.Properties.RoleArn['Fn::GetAtt'][0]).to.equal('IamRoleStateMachineExecution');
61+
.StateMachineBeta2.Properties.RoleArn['Fn::GetAtt'][0]).to.equal('StateMachineBeta2Role');
6262
expect(serverlessStepFunctions.serverless.service
6363
.provider.compiledCloudFormationTemplate.Resources
64-
.StateMachineBeta1.DependsOn).to.deep.eq(['IamRoleStateMachineExecution']);
64+
.StateMachineBeta1.DependsOn).to.deep.eq(['StateMachineBeta1Role']);
6565
expect(serverlessStepFunctions.serverless.service
6666
.provider.compiledCloudFormationTemplate.Resources
67-
.StateMachineBeta2.DependsOn).to.deep.eq(['IamRoleStateMachineExecution']);
67+
.StateMachineBeta2.DependsOn).to.deep.eq(['StateMachineBeta2Role']);
6868
expect(serverlessStepFunctions.serverless.service
6969
.provider.compiledCloudFormationTemplate.Outputs
7070
.StateMachineBeta1Arn.Value.Ref).to.equal('StateMachineBeta1');
@@ -100,16 +100,16 @@ describe('#compileStateMachines', () => {
100100
.MyStateMachine2StepFunctionsStateMachine.Properties.DefinitionString).to.equal('"definition2"');
101101
expect(serverlessStepFunctions.serverless.service
102102
.provider.compiledCloudFormationTemplate.Resources
103-
.MyStateMachine1StepFunctionsStateMachine.Properties.RoleArn['Fn::GetAtt'][0]).to.equal('IamRoleStateMachineExecution');
103+
.MyStateMachine1StepFunctionsStateMachine.Properties.RoleArn['Fn::GetAtt'][0]).to.equal('MyStateMachine1StepFunctionsStateMachineRole');
104104
expect(serverlessStepFunctions.serverless.service
105105
.provider.compiledCloudFormationTemplate.Resources
106-
.MyStateMachine2StepFunctionsStateMachine.Properties.RoleArn['Fn::GetAtt'][0]).to.equal('IamRoleStateMachineExecution');
106+
.MyStateMachine2StepFunctionsStateMachine.Properties.RoleArn['Fn::GetAtt'][0]).to.equal('MyStateMachine2StepFunctionsStateMachineRole');
107107
expect(serverlessStepFunctions.serverless.service
108108
.provider.compiledCloudFormationTemplate.Resources
109-
.MyStateMachine1StepFunctionsStateMachine.DependsOn).to.deep.eq(['IamRoleStateMachineExecution']);
109+
.MyStateMachine1StepFunctionsStateMachine.DependsOn).to.deep.eq(['MyStateMachine1StepFunctionsStateMachineRole']);
110110
expect(serverlessStepFunctions.serverless.service
111111
.provider.compiledCloudFormationTemplate.Resources
112-
.MyStateMachine2StepFunctionsStateMachine.DependsOn).to.deep.eq(['IamRoleStateMachineExecution']);
112+
.MyStateMachine2StepFunctionsStateMachine.DependsOn).to.deep.eq(['MyStateMachine2StepFunctionsStateMachineRole']);
113113
expect(serverlessStepFunctions.serverless.service
114114
.provider.compiledCloudFormationTemplate.Outputs
115115
.MyStateMachine1StepFunctionsStateMachineArn.Value.Ref).to.equal('MyStateMachine1StepFunctionsStateMachine');
@@ -147,16 +147,16 @@ describe('#compileStateMachines', () => {
147147
.StateMachineBeta2.Properties.DefinitionString).to.equal('"definition2"');
148148
expect(serverlessStepFunctions.serverless.service
149149
.provider.compiledCloudFormationTemplate.Resources
150-
.StateMachineBeta1.Properties.RoleArn['Fn::GetAtt'][0]).to.equal('IamRoleStateMachineExecution');
150+
.StateMachineBeta1.Properties.RoleArn['Fn::GetAtt'][0]).to.equal('StateMachineBeta1Role');
151151
expect(serverlessStepFunctions.serverless.service
152152
.provider.compiledCloudFormationTemplate.Resources
153-
.StateMachineBeta2.Properties.RoleArn['Fn::GetAtt'][0]).to.equal('IamRoleStateMachineExecution');
153+
.StateMachineBeta2.Properties.RoleArn['Fn::GetAtt'][0]).to.equal('StateMachineBeta2Role');
154154
expect(serverlessStepFunctions.serverless.service
155155
.provider.compiledCloudFormationTemplate.Resources
156-
.StateMachineBeta1.DependsOn).to.deep.eq(['IamRoleStateMachineExecution']);
156+
.StateMachineBeta1.DependsOn).to.deep.eq(['StateMachineBeta1Role']);
157157
expect(serverlessStepFunctions.serverless.service
158158
.provider.compiledCloudFormationTemplate.Resources
159-
.StateMachineBeta2.DependsOn).to.deep.eq(['IamRoleStateMachineExecution']);
159+
.StateMachineBeta2.DependsOn).to.deep.eq(['StateMachineBeta2Role']);
160160
});
161161

162162
it('should create corresponding resources when definition and role property are given', () => {
@@ -400,16 +400,16 @@ describe('#compileStateMachines', () => {
400400
.StateMachineBeta2.Properties.DefinitionString).to.equal('"definition2"');
401401
expect(serverlessStepFunctions.serverless.service
402402
.provider.compiledCloudFormationTemplate.Resources
403-
.StateMachineBeta1.Properties.RoleArn['Fn::GetAtt'][0]).to.equal('IamRoleStateMachineExecution');
403+
.StateMachineBeta1.Properties.RoleArn['Fn::GetAtt'][0]).to.equal('StateMachineBeta1Role');
404404
expect(serverlessStepFunctions.serverless.service
405405
.provider.compiledCloudFormationTemplate.Resources
406-
.StateMachineBeta2.Properties.RoleArn['Fn::GetAtt'][0]).to.equal('IamRoleStateMachineExecution');
406+
.StateMachineBeta2.Properties.RoleArn['Fn::GetAtt'][0]).to.equal('StateMachineBeta2Role');
407407
expect(serverlessStepFunctions.serverless.service
408408
.provider.compiledCloudFormationTemplate.Resources
409-
.StateMachineBeta1.DependsOn).to.deep.eq(['IamRoleStateMachineExecution', 'DynamoDBTable']);
409+
.StateMachineBeta1.DependsOn).to.deep.eq(['StateMachineBeta1Role', 'DynamoDBTable']);
410410
expect(serverlessStepFunctions.serverless.service
411411
.provider.compiledCloudFormationTemplate.Resources
412-
.StateMachineBeta2.DependsOn).to.deep.eq(['IamRoleStateMachineExecution', 'DynamoDBTable', 'KinesisStream']);
412+
.StateMachineBeta2.DependsOn).to.deep.eq(['StateMachineBeta2Role', 'DynamoDBTable', 'KinesisStream']);
413413
});
414414

415415
it('should throw error when dependsOn property is neither string nor [string]', () => {

0 commit comments

Comments
 (0)