@@ -2237,6 +2237,7 @@ export class GlobalConfig implements t.TypeOf<typeof GlobalConfigTypes.globalCon
22372237 const aseaStacks : t . AseaStackInfo [ ] = [ ] ;
22382238 for ( const account of mappingJson ) {
22392239 this . externalLandingZoneResources ?. accountsDeployedExternally . push ( account . accountId ) ;
2240+ let nestedStackPhysicalIds : string [ ] = [ ] ;
22402241 for ( const stack of account . stacksAndResourceMapList ) {
22412242 const phaseIdentifierIndex = stack . stackName . indexOf ( 'Phase' ) + 5 ;
22422243 let phase = stack . stackName [ phaseIdentifierIndex ] ;
@@ -2249,6 +2250,11 @@ export class GlobalConfig implements t.TypeOf<typeof GlobalConfigTypes.globalCon
22492250 // Delete outputs from template. IMPORT_ASEA_RESOURCES stage will write required information into SSM Parameter Store.
22502251 // delete stack.template.Outputs;
22512252 await fs . promises . writeFile ( templatePath , JSON . stringify ( stack . template , null , 2 ) ) ;
2253+ for ( const cfnResource of stack . resourceMap ) {
2254+ if ( cfnResource . resourceType == 'AWS::CloudFormation::Stack' ) {
2255+ nestedStackPhysicalIds . push ( cfnResource . physicalResourceId ) ;
2256+ }
2257+ }
22522258 aseaStacks . push ( {
22532259 accountId : account . accountId ,
22542260 accountKey : account . accountKey ,
@@ -2257,14 +2263,15 @@ export class GlobalConfig implements t.TypeOf<typeof GlobalConfigTypes.globalCon
22572263 resources : stack . resourceMap as t . CfnResourceType [ ] ,
22582264 templatePath,
22592265 phase,
2260- /**
2261- * ASEA creates Nested stacks only for Phase1 and Phase2 and "stack.stackName.substring(phaseIdentifierIndex)" doesn't include accountName in it.
2262- * It is safe to use string include to check if stack is nestedStack or not.
2263- * Other option is to check for resource type in "Resources.physicalResourceId" using stackName
2264- */
2265- nestedStack : stack . stackName . substring ( phaseIdentifierIndex ) . includes ( 'NestedStack' ) ,
2266+ nestedStack : stack . parentStack ? true : false ,
22662267 } ) ;
22672268 }
2269+ for ( const physicalId of nestedStackPhysicalIds ) {
2270+ const nestedStack = aseaStacks . findIndex ( ( stack ) => physicalId . includes ( `:stack/${ stack . stackName } /` ) ) ;
2271+ if ( nestedStack > - 1 ) {
2272+ aseaStacks [ nestedStack ] . nestedStack = true ;
2273+ }
2274+ }
22682275 }
22692276 return aseaStacks ;
22702277 }
0 commit comments