11import { DataLandingZoneProps , DlzAllRegions } from '../../data-landing-zone-types' ;
22import { assumeRole , runCommand } from '../lib/helpers' ;
3+ import { synth } from '../synth' ;
34
45const tags = '--tags Owner=infra --tags Project=dlz --tags Environment=dlz' ;
56
@@ -13,6 +14,7 @@ async function bootstrapChildAccount(props: DataLandingZoneProps, bootstrapRoleN
1314 `--trust ${ props . organization . root . accounts . management . accountId } ` ,
1415 tags ,
1516 `aws://${ accountId } /${ region } ` ,
17+ '--app cdk.out' ,
1618 ] . join ( ' ' ) ,
1719 {
1820 env : {
@@ -22,34 +24,56 @@ async function bootstrapChildAccount(props: DataLandingZoneProps, bootstrapRoleN
2224 AWS_SECRET_ACCESS_KEY : accountCreds . SecretAccessKey ! ,
2325 AWS_SESSION_TOKEN : accountCreds . SessionToken ! ,
2426 } ,
25- } ) ;
27+ } ,
28+ `(${ region } ) ` ) ;
29+ }
30+
31+ let bootstrapSynthed = false ;
32+ async function synthOnce ( props : DataLandingZoneProps ) {
33+ if ( ! bootstrapSynthed ) {
34+ bootstrapSynthed = true ;
35+ await synth ( props ) ;
36+ }
2637}
2738
2839async function management ( props : DataLandingZoneProps ) {
40+ await synthOnce ( props ) ;
2941 await runCommand ( 'cdk' , [
3042 'bootstrap' ,
3143 '--cloudformation-execution-policies arn:aws:iam::aws:policy/AdministratorAccess' ,
3244 `--profile ${ props . localProfile } ` ,
3345 tags ,
3446 `aws://${ props . organization . root . accounts . management . accountId } /${ props . regions . global } ` ,
47+ '--app cdk.out' ,
3548 ] . join ( ' ' ) ) ;
3649}
3750async function log ( props : DataLandingZoneProps , bootstrapRoleName : string = 'AWSControlTowerExecution' ) {
51+ await synthOnce ( props ) ;
52+
53+ const regionBootStrapPromises = [ ] ;
3854 for ( let region of DlzAllRegions ( props . regions ) ) {
39- await bootstrapChildAccount ( props , bootstrapRoleName , props . organization . ous . security . accounts . log . accountId , region ) ;
55+ regionBootStrapPromises . push ( bootstrapChildAccount ( props , bootstrapRoleName , props . organization . ous . security . accounts . log . accountId , region ) ) ;
4056 }
57+ await Promise . all ( regionBootStrapPromises ) ;
4158}
4259async function audit ( props : DataLandingZoneProps , bootstrapRoleName : string = 'AWSControlTowerExecution' ) {
60+ await synthOnce ( props ) ;
61+
62+ const regionBootStrapPromises = [ ] ;
4363 for ( let region of DlzAllRegions ( props . regions ) ) {
44- await bootstrapChildAccount ( props , bootstrapRoleName , props . organization . ous . security . accounts . audit . accountId , region ) ;
64+ regionBootStrapPromises . push ( bootstrapChildAccount ( props , bootstrapRoleName , props . organization . ous . security . accounts . audit . accountId , region ) ) ;
4565 }
66+ await Promise . all ( regionBootStrapPromises ) ;
4667}
47-
4868async function workloadAccounts ( props : DataLandingZoneProps , bootstrapRoleName : string = 'AWSControlTowerExecution' ) {
69+ await synthOnce ( props ) ;
70+
4971 for ( const account of props . organization . ous . workloads . accounts ) {
72+ const regionBootStrapPromises = [ ] ;
5073 for ( let region of DlzAllRegions ( props . regions ) ) {
51- await bootstrapChildAccount ( props , bootstrapRoleName , account . accountId , region ) ;
74+ regionBootStrapPromises . push ( bootstrapChildAccount ( props , bootstrapRoleName , account . accountId , region ) ) ;
5275 }
76+ await Promise . all ( regionBootStrapPromises ) ;
5377 }
5478}
5579
0 commit comments