Skip to content

Commit

Permalink
fix: exec role is no longer hardcoded
Browse files Browse the repository at this point in the history
  • Loading branch information
theburningmonk committed Dec 23, 2019
1 parent c54edd3 commit 332f0a1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
10 changes: 6 additions & 4 deletions lib/deploy/stepFunctions/compileStateMachines.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ module.exports = {
if (this.isStateMachines()) {
this.getAllStateMachines().forEach((stateMachineName) => {
const stateMachineObj = this.getStateMachine(stateMachineName);
const stateMachineLogicalId = this.getStateMachineLogicalId(stateMachineName,
stateMachineObj);
let DefinitionString;
let RoleArn;
let DependsOn = [];
Expand Down Expand Up @@ -158,13 +160,14 @@ module.exports = {
if (stateMachineObj.role) {
RoleArn = stateMachineObj.role;
} else {
const roleLogicalId = `${stateMachineLogicalId}Role`;
RoleArn = {
'Fn::GetAtt': [
'IamRoleStateMachineExecution',
roleLogicalId,
'Arn',
],
};
DependsOn.push('IamRoleStateMachineExecution');
DependsOn.push(roleLogicalId);
}

if (stateMachineObj.dependsOn) {
Expand Down Expand Up @@ -196,8 +199,7 @@ module.exports = {
};
}

const stateMachineLogicalId = this.getStateMachineLogicalId(stateMachineName,
stateMachineObj);

const stateMachineOutputLogicalId = this
.getStateMachineOutputLogicalId(stateMachineName, stateMachineObj);
const stateMachineTemplate = {
Expand Down
32 changes: 16 additions & 16 deletions lib/deploy/stepFunctions/compileStateMachines.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,16 @@ describe('#compileStateMachines', () => {
.StateMachineBeta2.Properties.DefinitionString).to.equal('"definition2"');
expect(serverlessStepFunctions.serverless.service
.provider.compiledCloudFormationTemplate.Resources
.StateMachineBeta1.Properties.RoleArn['Fn::GetAtt'][0]).to.equal('IamRoleStateMachineExecution');
.StateMachineBeta1.Properties.RoleArn['Fn::GetAtt'][0]).to.equal('StateMachineBeta1Role');
expect(serverlessStepFunctions.serverless.service
.provider.compiledCloudFormationTemplate.Resources
.StateMachineBeta2.Properties.RoleArn['Fn::GetAtt'][0]).to.equal('IamRoleStateMachineExecution');
.StateMachineBeta2.Properties.RoleArn['Fn::GetAtt'][0]).to.equal('StateMachineBeta2Role');
expect(serverlessStepFunctions.serverless.service
.provider.compiledCloudFormationTemplate.Resources
.StateMachineBeta1.DependsOn).to.deep.eq(['IamRoleStateMachineExecution']);
.StateMachineBeta1.DependsOn).to.deep.eq(['StateMachineBeta1Role']);
expect(serverlessStepFunctions.serverless.service
.provider.compiledCloudFormationTemplate.Resources
.StateMachineBeta2.DependsOn).to.deep.eq(['IamRoleStateMachineExecution']);
.StateMachineBeta2.DependsOn).to.deep.eq(['StateMachineBeta2Role']);
expect(serverlessStepFunctions.serverless.service
.provider.compiledCloudFormationTemplate.Outputs
.StateMachineBeta1Arn.Value.Ref).to.equal('StateMachineBeta1');
Expand Down Expand Up @@ -100,16 +100,16 @@ describe('#compileStateMachines', () => {
.MyStateMachine2StepFunctionsStateMachine.Properties.DefinitionString).to.equal('"definition2"');
expect(serverlessStepFunctions.serverless.service
.provider.compiledCloudFormationTemplate.Resources
.MyStateMachine1StepFunctionsStateMachine.Properties.RoleArn['Fn::GetAtt'][0]).to.equal('IamRoleStateMachineExecution');
.MyStateMachine1StepFunctionsStateMachine.Properties.RoleArn['Fn::GetAtt'][0]).to.equal('MyStateMachine1StepFunctionsStateMachineRole');
expect(serverlessStepFunctions.serverless.service
.provider.compiledCloudFormationTemplate.Resources
.MyStateMachine2StepFunctionsStateMachine.Properties.RoleArn['Fn::GetAtt'][0]).to.equal('IamRoleStateMachineExecution');
.MyStateMachine2StepFunctionsStateMachine.Properties.RoleArn['Fn::GetAtt'][0]).to.equal('MyStateMachine2StepFunctionsStateMachineRole');
expect(serverlessStepFunctions.serverless.service
.provider.compiledCloudFormationTemplate.Resources
.MyStateMachine1StepFunctionsStateMachine.DependsOn).to.deep.eq(['IamRoleStateMachineExecution']);
.MyStateMachine1StepFunctionsStateMachine.DependsOn).to.deep.eq(['MyStateMachine1StepFunctionsStateMachineRole']);
expect(serverlessStepFunctions.serverless.service
.provider.compiledCloudFormationTemplate.Resources
.MyStateMachine2StepFunctionsStateMachine.DependsOn).to.deep.eq(['IamRoleStateMachineExecution']);
.MyStateMachine2StepFunctionsStateMachine.DependsOn).to.deep.eq(['MyStateMachine2StepFunctionsStateMachineRole']);
expect(serverlessStepFunctions.serverless.service
.provider.compiledCloudFormationTemplate.Outputs
.MyStateMachine1StepFunctionsStateMachineArn.Value.Ref).to.equal('MyStateMachine1StepFunctionsStateMachine');
Expand Down Expand Up @@ -147,16 +147,16 @@ describe('#compileStateMachines', () => {
.StateMachineBeta2.Properties.DefinitionString).to.equal('"definition2"');
expect(serverlessStepFunctions.serverless.service
.provider.compiledCloudFormationTemplate.Resources
.StateMachineBeta1.Properties.RoleArn['Fn::GetAtt'][0]).to.equal('IamRoleStateMachineExecution');
.StateMachineBeta1.Properties.RoleArn['Fn::GetAtt'][0]).to.equal('StateMachineBeta1Role');
expect(serverlessStepFunctions.serverless.service
.provider.compiledCloudFormationTemplate.Resources
.StateMachineBeta2.Properties.RoleArn['Fn::GetAtt'][0]).to.equal('IamRoleStateMachineExecution');
.StateMachineBeta2.Properties.RoleArn['Fn::GetAtt'][0]).to.equal('StateMachineBeta2Role');
expect(serverlessStepFunctions.serverless.service
.provider.compiledCloudFormationTemplate.Resources
.StateMachineBeta1.DependsOn).to.deep.eq(['IamRoleStateMachineExecution']);
.StateMachineBeta1.DependsOn).to.deep.eq(['StateMachineBeta1Role']);
expect(serverlessStepFunctions.serverless.service
.provider.compiledCloudFormationTemplate.Resources
.StateMachineBeta2.DependsOn).to.deep.eq(['IamRoleStateMachineExecution']);
.StateMachineBeta2.DependsOn).to.deep.eq(['StateMachineBeta2Role']);
});

it('should create corresponding resources when definition and role property are given', () => {
Expand Down Expand Up @@ -400,16 +400,16 @@ describe('#compileStateMachines', () => {
.StateMachineBeta2.Properties.DefinitionString).to.equal('"definition2"');
expect(serverlessStepFunctions.serverless.service
.provider.compiledCloudFormationTemplate.Resources
.StateMachineBeta1.Properties.RoleArn['Fn::GetAtt'][0]).to.equal('IamRoleStateMachineExecution');
.StateMachineBeta1.Properties.RoleArn['Fn::GetAtt'][0]).to.equal('StateMachineBeta1Role');
expect(serverlessStepFunctions.serverless.service
.provider.compiledCloudFormationTemplate.Resources
.StateMachineBeta2.Properties.RoleArn['Fn::GetAtt'][0]).to.equal('IamRoleStateMachineExecution');
.StateMachineBeta2.Properties.RoleArn['Fn::GetAtt'][0]).to.equal('StateMachineBeta2Role');
expect(serverlessStepFunctions.serverless.service
.provider.compiledCloudFormationTemplate.Resources
.StateMachineBeta1.DependsOn).to.deep.eq(['IamRoleStateMachineExecution', 'DynamoDBTable']);
.StateMachineBeta1.DependsOn).to.deep.eq(['StateMachineBeta1Role', 'DynamoDBTable']);
expect(serverlessStepFunctions.serverless.service
.provider.compiledCloudFormationTemplate.Resources
.StateMachineBeta2.DependsOn).to.deep.eq(['IamRoleStateMachineExecution', 'DynamoDBTable', 'KinesisStream']);
.StateMachineBeta2.DependsOn).to.deep.eq(['StateMachineBeta2Role', 'DynamoDBTable', 'KinesisStream']);
});

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

0 comments on commit 332f0a1

Please sign in to comment.