@@ -900,4 +900,85 @@ describe('#compileIamRole', () => {
900900 . Properties . Policies [ 0 ] ;
901901 expectDenyAllPolicy ( policy ) ;
902902 } ) ;
903+
904+ it ( 'should respect CloudFormation intrinsic functions for Resource' , ( ) => {
905+ serverless . service . stepFunctions = {
906+ stateMachines : {
907+ myStateMachine : {
908+ name : 'stateMachine' ,
909+ definition : {
910+ StartAt : 'Lambda' ,
911+ States : {
912+ Lambda : {
913+ Type : 'Task' ,
914+ Resource : {
915+ Ref : 'MyFunction' ,
916+ } ,
917+ Next : 'Sns' ,
918+ } ,
919+ Sns : {
920+ Type : 'Task' ,
921+ Resource : 'arn:aws:states:::sns:publish' ,
922+ Parameters : {
923+ Message : {
924+ 'Fn::GetAtt' : [ 'MyTopic' , 'TopicName' ] ,
925+ } ,
926+ TopicArn : {
927+ Ref : 'MyTopic' ,
928+ } ,
929+ } ,
930+ Next : 'Sqs' ,
931+ } ,
932+ Sqs : {
933+ Type : 'Task' ,
934+ Resource : 'arn:aws:states:::sqs:sendMessage' ,
935+ Parameters : {
936+ QueueUrl : {
937+ Ref : 'MyQueue' ,
938+ } ,
939+ MessageBody : 'This is a static message' ,
940+ } ,
941+ Next : 'Parallel' ,
942+ } ,
943+ Parallel : {
944+ Type : 'Parallel' ,
945+ End : true ,
946+ Branches : [
947+ {
948+ StartAt : 'Lambda2' ,
949+ States : {
950+ Lambda2 : {
951+ Type : 'Task' ,
952+ Resource : {
953+ Ref : 'MyFunction2' ,
954+ } ,
955+ End : true ,
956+ } ,
957+ } ,
958+ } ,
959+ ] ,
960+ } ,
961+ } ,
962+ } ,
963+ } ,
964+ } ,
965+ } ;
966+
967+ serverlessStepFunctions . compileIamRole ( ) ;
968+ serverlessStepFunctions . compileStateMachines ( ) ;
969+ const policy = serverlessStepFunctions . serverless . service
970+ . provider . compiledCloudFormationTemplate . Resources . IamRoleStateMachineExecution
971+ . Properties . Policies [ 0 ] ;
972+
973+ const statements = policy . PolicyDocument . Statement ;
974+ const lambdaPermissions = statements . find ( x => x . Action [ 0 ] === 'lambda:InvokeFunction' ) ;
975+ expect ( lambdaPermissions . Resource ) . to . be . deep . equal ( [
976+ { Ref : 'MyFunction' } , { Ref : 'MyFunction2' } ] ) ;
977+ const snsPermissions = statements . find ( x => x . Action [ 0 ] === 'sns:Publish' ) ;
978+ expect ( snsPermissions . Resource ) . to . be . deep . equal ( [ { Ref : 'MyTopic' } ] ) ;
979+ const sqsPermissions = statements . find ( x => x . Action [ 0 ] === 'sqs:SendMessage' ) ;
980+ expect ( sqsPermissions . Resource ) . to . be . deep . equal ( [ {
981+ 'Fn::GetAtt' : [ 'MyQueue' , 'Arn' ] ,
982+ } ] ) ;
983+ } ) ;
903984} ) ;
0 commit comments