@@ -375,55 +375,53 @@ function getIamStatements(iamPermissions) {
375
375
376
376
module . exports = {
377
377
compileIamRole ( ) {
378
- const customRolesProvided = [ ] ;
379
- let iamPermissions = [ ] ;
380
- let hasExpressWorkflow = false ;
381
378
this . getAllStateMachines ( ) . forEach ( ( stateMachineName ) => {
382
379
const stateMachineObj = this . getStateMachine ( stateMachineName ) ;
383
- customRolesProvided . push ( 'role' in stateMachineObj ) ;
380
+ if ( stateMachineObj . role ) {
381
+ return ;
382
+ }
384
383
385
384
const taskStates = getTaskStates ( stateMachineObj . definition . States ) ;
386
- iamPermissions = iamPermissions . concat ( getIamPermissions . bind ( this ) ( taskStates ) ) ;
385
+ let iamPermissions = getIamPermissions . bind ( this ) ( taskStates ) ;
387
386
388
387
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
+ } ) ;
390
392
}
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
- ) ;
409
393
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
+ } ;
419
418
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
+ } ) ;
424
424
425
- _ . merge ( this . serverless . service . provider . compiledCloudFormationTemplate . Resources ,
426
- newIamRoleStateMachineExecutionObject ) ;
427
425
return BbPromise . resolve ( ) ;
428
426
} ,
429
427
} ;
0 commit comments