@@ -71,8 +71,10 @@ export interface IamPolicyArtifactsOutput {
7171export async function deploy ( { acceleratorConfig, accountStacks, accounts, context, limiter, outputs } : PhaseInput ) {
7272 const mandatoryAccountConfig = acceleratorConfig . getMandatoryAccountConfigs ( ) ;
7373 const orgUnits = acceleratorConfig . getOrganizationalUnits ( ) ;
74+ const workLoadAccountConfig = acceleratorConfig . getWorkloadAccountConfigs ( ) ;
7475 const masterAccountKey = acceleratorConfig . getMandatoryAccountKey ( 'master' ) ;
7576 const logAccountKey = acceleratorConfig . getMandatoryAccountKey ( 'central-log' ) ;
77+ const iamConfigs = acceleratorConfig . getIamConfigs ( ) ;
7678 const masterAccountId = getAccountId ( accounts , masterAccountKey ) ;
7779 if ( ! masterAccountId ) {
7880 throw new Error ( `Cannot find mandatory primary account ${ masterAccountKey } ` ) ;
@@ -317,8 +319,7 @@ export async function deploy({ acceleratorConfig, accountStacks, accounts, conte
317319 const iamPoliciesBucketName = iamPolicyArtifactOutput [ 0 ] . bucketName ;
318320 const iamPoliciesBucketPrefix = iamPolicyArtifactOutput [ 0 ] . keyPrefix + '/' ;
319321
320- for ( const [ accountKey , accountConfig ] of mandatoryAccountConfig ) {
321- const iamConfig = accountConfig . iam ;
322+ for ( const { iam : iamConfig } of iamConfigs ) {
322323 if ( IamConfigType . is ( iamConfig ) ) {
323324 const iamPolicies = iamConfig ?. policies ;
324325 for ( const iamPolicy of iamPolicies || [ ] ) {
@@ -367,7 +368,7 @@ export async function deploy({ acceleratorConfig, accountStacks, accounts, conte
367368 }
368369
369370 if ( iamPoliciesDefinition ) {
370- const iamAssets = new IamAssets ( accountStack , `IAM Assets-${ pascalCase ( accountKey ) } ` , {
371+ new IamAssets ( accountStack , `IAM Assets-${ pascalCase ( accountKey ) } ` , {
371372 accountKey,
372373 iamConfig,
373374 iamPoliciesDefinition,
@@ -378,31 +379,36 @@ export async function deploy({ acceleratorConfig, accountStacks, accounts, conte
378379 }
379380 } ;
380381
381- const getNonMandatoryAccountsPerOu = ( ouName : string , mandatoryAccKeys : string [ ] ) : Account [ ] => {
382- const accountsPerOu : Account [ ] = [ ] ;
383- for ( const account of accounts ) {
384- if ( account . ou === ouName && ! mandatoryAccKeys . includes ( account . key ) ) {
385- accountsPerOu . push ( account ) ;
382+ const accountIamConfigs : { [ accountKey : string ] : IamConfig } = { } ;
383+ for ( const { accountKey, iam : iamConfig } of iamConfigs ) {
384+ if ( accountIamConfigs [ accountKey ] ) {
385+ if ( accountIamConfigs [ accountKey ] . policies ) {
386+ accountIamConfigs [ accountKey ] . policies ?. push ( ...( iamConfig . policies || [ ] ) ) ;
387+ } else {
388+ accountIamConfigs [ accountKey ] . policies = iamConfig . policies ;
386389 }
387- }
388- return accountsPerOu ;
389- } ;
390390
391- const mandatoryAccountKeys : string [ ] = [ ] ;
392- // creating assets for default account settings
393- for ( const [ accountKey , accountConfig ] of mandatoryAccountConfig ) {
394- mandatoryAccountKeys . push ( accountKey ) ;
395- await createIamAssets ( accountKey , accountConfig . iam ) ;
396- }
391+ if ( accountIamConfigs [ accountKey ] . roles ) {
392+ accountIamConfigs [ accountKey ] . roles ?. push ( ...( iamConfig . roles || [ ] ) ) ;
393+ } else {
394+ accountIamConfigs [ accountKey ] . roles = iamConfig . roles ;
395+ }
397396
398- // creating assets for org unit accounts
399- for ( const [ orgName , orgConfig ] of orgUnits ) {
400- const orgAccounts = getNonMandatoryAccountsPerOu ( orgName , mandatoryAccountKeys ) ;
401- for ( const orgAccount of orgAccounts ) {
402- await createIamAssets ( orgAccount . key , orgConfig . iam ) ;
397+ if ( accountIamConfigs [ accountKey ] . users ) {
398+ accountIamConfigs [ accountKey ] . users ?. push ( ...( iamConfig . users || [ ] ) ) ;
399+ } else {
400+ accountIamConfigs [ accountKey ] . users = iamConfig . users ;
401+ }
402+ } else {
403+ accountIamConfigs [ accountKey ] = iamConfig ;
403404 }
404405 }
405406
407+ // creating assets for default account settings
408+ for ( const [ accountKey , iamConfig ] of Object . entries ( accountIamConfigs ) ) {
409+ await createIamAssets ( accountKey , iamConfig ) ;
410+ }
411+
406412 // Budget creation step 2
407413 await budget . step2 ( {
408414 accountStacks,
0 commit comments