@@ -206,6 +206,7 @@ export namespace InitialSetup {
206206 'phases.$' : '$.configuration.baselineOutput.phases' ,
207207 'acceleratorVersion.$' : '$.configuration.acceleratorVersion' ,
208208 'configRootFilePath.$' : '$.configuration.configRootFilePath' ,
209+ 'organizationAdmiRole.$' : '$.configuration.baselineOutput.organizationAdmiRole' ,
209210 } ,
210211 resultPath : '$.configuration' ,
211212 } ) ;
@@ -225,6 +226,7 @@ export namespace InitialSetup {
225226 'phases.$' : '$.configuration.baselineOutput.phases' ,
226227 'acceleratorVersion.$' : '$.configuration.acceleratorVersion' ,
227228 'configRootFilePath.$' : '$.configuration.configRootFilePath' ,
229+ 'organizationAdmiRole.$' : '$.configuration.baselineOutput.organizationAdmiRole' ,
228230 } ,
229231 resultPath : '$.configuration' ,
230232 } ) ;
@@ -350,6 +352,7 @@ export namespace InitialSetup {
350352 'regions.$' : '$.configuration.regions' ,
351353 'accounts.$' : '$.configuration.accounts' ,
352354 'configRootFilePath.$' : '$.configuration.configRootFilePath' ,
355+ 'organizationAdmiRole.$' : '$.configuration.organizationAdmiRole' ,
353356 } ,
354357 resultPath : '$' ,
355358 } ) ;
@@ -389,18 +392,15 @@ export namespace InitialSetup {
389392 } ,
390393 ) ;
391394
392- const installRoleTemplate = new s3assets . Asset ( this , 'ExecutionRoleTemplate' , {
393- path : path . join ( __dirname , 'assets' , 'execution-role.template.json' ) ,
394- } ) ;
395-
396- // Make sure the Lambda can read the template
397- installRoleTemplate . bucket . grantRead ( pipelineRole ) ;
395+ const accountsPath = path . join ( __dirname , 'assets' , 'execution-role.template.json' ) ;
396+ const executionRoleContent = fs . readFileSync ( accountsPath ) ;
398397
399398 const installRolesStateMachine = new sfn . StateMachine ( this , `${ props . acceleratorPrefix } InstallRoles_sm` , {
400399 stateMachineName : `${ props . acceleratorPrefix } InstallRoles_sm` ,
401- definition : new CreateStackSetTask ( this , 'Install' , {
400+ definition : new CreateStackTask ( this , 'Install' , {
402401 lambdaCode,
403402 role : pipelineRole ,
403+ suffix : 'ExecutionRole' ,
404404 } ) ,
405405 } ) ;
406406
@@ -416,16 +416,25 @@ export namespace InitialSetup {
416416 // TODO Only add root role for development environments
417417 AssumedByRoleArn : `arn:aws:iam::${ stack . account } :root,${ pipelineRole . roleArn } ` ,
418418 } ,
419- stackTemplate : {
420- s3BucketName : installRoleTemplate . s3BucketName ,
421- s3ObjectKey : installRoleTemplate . s3ObjectKey ,
422- } ,
423- 'instanceAccounts.$' : '$.accounts' ,
424- instanceRegions : [ stack . region ] ,
419+ stackTemplate : executionRoleContent . toString ( ) ,
420+ 'accountId.$' : '$.accountId' ,
421+ 'assumedRoleName.$' : '$.organizationAdmiRole' ,
425422 } ) ,
426423 resultPath : 'DISCARD' ,
427424 } ) ;
428425
426+ const installExecRolesInAccounts = new sfn . Map ( this , `Install Execution Roles Map` , {
427+ itemsPath : '$.accounts' ,
428+ resultPath : 'DISCARD' ,
429+ maxConcurrency : 40 ,
430+ parameters : {
431+ 'accountId.$' : '$$.Map.Item.Value' ,
432+ 'organizationAdmiRole.$' : '$.organizationAdmiRole' ,
433+ } ,
434+ } ) ;
435+
436+ installExecRolesInAccounts . iterator ( installRolesTask ) ;
437+
429438 const deleteVpcSfn = new sfn . StateMachine ( this , 'Delete Default Vpcs Sfn' , {
430439 stateMachineName : `${ props . acceleratorPrefix } DeleteDefaultVpcs_sfn` ,
431440 definition : new RunAcrossAccountsTask ( this , 'DeleteDefaultVPCs' , {
@@ -853,7 +862,7 @@ export namespace InitialSetup {
853862
854863 const commonDefinition = loadOrganizationsTask . startState
855864 . next ( loadAccountsTask )
856- . next ( installRolesTask )
865+ . next ( installExecRolesInAccounts )
857866 . next ( deleteVpcTask )
858867 . next ( loadLimitsTask )
859868 . next ( enableTrustedAccessForServicesTask )
0 commit comments