@@ -375,55 +375,53 @@ function getIamStatements(iamPermissions) {
375375
376376module . exports = {
377377 compileIamRole ( ) {
378- const customRolesProvided = [ ] ;
379- let iamPermissions = [ ] ;
380- let hasExpressWorkflow = false ;
381378 this . getAllStateMachines ( ) . forEach ( ( stateMachineName ) => {
382379 const stateMachineObj = this . getStateMachine ( stateMachineName ) ;
383- customRolesProvided . push ( 'role' in stateMachineObj ) ;
380+ if ( stateMachineObj . role ) {
381+ return ;
382+ }
384383
385384 const taskStates = getTaskStates ( stateMachineObj . definition . States ) ;
386- iamPermissions = iamPermissions . concat ( getIamPermissions . bind ( this ) ( taskStates ) ) ;
385+ let iamPermissions = getIamPermissions . bind ( this ) ( taskStates ) ;
387386
388387 if ( stateMachineObj . type === 'EXPRESS' ) {
389- hasExpressWorkflow = true ;
388+ iamPermissions . push ( {
389+ action : 'logs:CreateLogDelivery,logs:GetLogDelivery,logs:UpdateLogDelivery,logs:DeleteLogDelivery,logs:ListLogDeliveries,logs:PutResourcePolicy,logs:DescribeResourcePolicies,logs:DescribeLogGroups' ,
390+ resource : '*' ,
391+ } ) ;
390392 }
391- } ) ;
392- if ( _ . isEqual ( _ . uniq ( customRolesProvided ) , [ true ] ) ) {
393- return BbPromise . resolve ( ) ;
394- }
395-
396- if ( hasExpressWorkflow ) {
397- iamPermissions . push ( {
398- action : 'logs:CreateLogDelivery,logs:GetLogDelivery,logs:UpdateLogDelivery,logs:DeleteLogDelivery,logs:ListLogDeliveries,logs:PutResourcePolicy,logs:DescribeResourcePolicies,logs:DescribeLogGroups' ,
399- resource : '*' ,
400- } ) ;
401- }
402-
403- const iamRoleStateMachineExecutionTemplate = this . serverless . utils . readFileSync (
404- path . join ( __dirname ,
405- '..' ,
406- '..' ,
407- 'iam-role-statemachine-execution-template.txt' ) ,
408- ) ;
409393
410- iamPermissions = consolidatePermissionsByAction ( iamPermissions ) ;
411- iamPermissions = consolidatePermissionsByResource ( iamPermissions ) ;
412-
413- const iamStatements = getIamStatements ( iamPermissions ) ;
414-
415- const iamRoleJson = iamRoleStateMachineExecutionTemplate
416- . replace ( '[region]' , this . options . region )
417- . replace ( '[PolicyName]' , this . getStateMachinePolicyName ( ) )
418- . replace ( '[Statements]' , JSON . stringify ( iamStatements ) ) ;
394+ iamPermissions = consolidatePermissionsByAction ( iamPermissions ) ;
395+ iamPermissions = consolidatePermissionsByResource ( iamPermissions ) ;
396+ const iamStatements = getIamStatements ( iamPermissions ) ;
397+
398+ const iamRoleStateMachineExecutionTemplate = this . serverless . utils . readFileSync (
399+ path . join ( __dirname ,
400+ '..' ,
401+ '..' ,
402+ 'iam-role-statemachine-execution-template.txt' ) ,
403+ ) ;
404+
405+ const iamRoleJson = iamRoleStateMachineExecutionTemplate
406+ . replace ( '[region]' , this . options . region )
407+ . replace ( '[PolicyName]' , this . getStateMachinePolicyName ( ) )
408+ . replace ( '[Statements]' , JSON . stringify ( iamStatements ) ) ;
409+
410+ const stateMachineLogicalId = this . getStateMachineLogicalId (
411+ stateMachineName ,
412+ stateMachineObj ,
413+ ) ;
414+ const iamRoleStateMachineLogicalId = `${ stateMachineLogicalId } Role` ;
415+ const newIamRoleStateMachineExecutionObject = {
416+ [ iamRoleStateMachineLogicalId ] : JSON . parse ( iamRoleJson ) ,
417+ } ;
419418
420- const iamRoleStateMachineLogicalId = this . getiamRoleStateMachineLogicalId ( ) ;
421- const newIamRoleStateMachineExecutionObject = {
422- [ iamRoleStateMachineLogicalId ] : JSON . parse ( iamRoleJson ) ,
423- } ;
419+ _ . merge (
420+ this . serverless . service . provider . compiledCloudFormationTemplate . Resources ,
421+ newIamRoleStateMachineExecutionObject ,
422+ ) ;
423+ } ) ;
424424
425- _ . merge ( this . serverless . service . provider . compiledCloudFormationTemplate . Resources ,
426- newIamRoleStateMachineExecutionObject ) ;
427425 return BbPromise . resolve ( ) ;
428426 } ,
429427} ;
0 commit comments