Skip to content

Commit

Permalink
added parent stack to stack metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
hickeydh-aws committed Feb 24, 2025
1 parent 804a8a2 commit bbbe686
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export class ResourceMapping {
};
}
async getEnvironmentStacks(environments: Environment[], cfnClientMap: Map<string, CfnClients>) {
const stackMap = new Map<string, string[]>();
const stackMap = new Map<string, {stackName: string, parentStack: string | undefined}[]>();
const stackListPromises = environments.map((environment) => {
const cfnClient = cfnClientMap.get(`${environment.accountId}-${environment.region}`);
if (!cfnClient) {
Expand All @@ -244,7 +244,7 @@ export class ResourceMapping {

async getEnvironmentMetaData(
environments: Environment[],
stackMap: Map<string, string[]>,
stackMap: Map<string, { stackName: string, parentStack: string | undefined }[]>,
cfnClientMap: Map<string, CfnClients>,
) {
const stackAndResourceMap = new Map<string, StacksAndResourceMap>();
Expand All @@ -262,7 +262,7 @@ export class ResourceMapping {
if (!stack?.stack || !stack.cfnClient) {
return undefined;
}
return this.getStackMetadata(stack.environment, stack.stack, stack.cfnClient.cfn, stack.cfnClient.cfnNative);
return this.getStackMetadata(stack.environment, stack.stack.stackName, stack.cfnClient.cfn, stack.cfnClient.cfnNative, stack.stack.parentStack);
});
const validStackAndResourcePromises = stackAndResourcesMapPromises.filter(
(stackAndResource): stackAndResource is Promise<StacksAndResourceMap> => stackAndResource !== undefined,
Expand Down Expand Up @@ -309,7 +309,7 @@ export class ResourceMapping {
(nestedStackAndResource) =>
stackAndResource.environment.accountId === nestedStackAndResource.environment.accountId &&
stackAndResource.environment.region === nestedStackAndResource.environment.region &&
nestedStackAndResource.stackName.includes(stackAndResource.stackName),
nestedStackAndResource.parentStack?.includes(stackAndResource.stackName),
);
if (matchedStacks.length === 0) {
return;
Expand Down Expand Up @@ -461,6 +461,7 @@ export class ResourceMapping {
stack: string,
cloudformation: CloudFormation,
cfnNative: aws.CloudFormation,
parentStack?: string
): Promise<StacksAndResourceMap> {
const stackResources = await this.describeCloudFormationStack(cloudformation, stack);
const cfTemplate = await cfnNative
Expand Down Expand Up @@ -496,6 +497,7 @@ export class ResourceMapping {
numberOfResourcesInTemplate: cfTemplateResourceCount,
resourceMap: stackResources,
template: cfTemplateObject,
parentStack
};
}

Expand Down Expand Up @@ -664,7 +666,7 @@ export class ResourceMapping {
}

async getStackList(cloudformation: CloudFormation, environment: Environment) {
const stacks: string[] = [];
const stacks: {stackName: string, parentStack: string | undefined}[] = [];
let nextToken: string | undefined;
do {
const response = await cloudformation
Expand All @@ -680,8 +682,8 @@ export class ResourceMapping {
})
.promise();
for (const stackSummary of response.StackSummaries || []) {
if (stackSummary.StackName.includes('Phase')|| stackSummary.ParentId?.includes("Phase")) {
stacks.push(stackSummary.StackName);
if (stackSummary.StackName.includes('Phase') || stackSummary.ParentId?.includes("Phase")) {
stacks.push({stackName: stackSummary.StackName, parentStack: stackSummary.ParentId});
}
}
nextToken = response.NextToken;
Expand Down

0 comments on commit bbbe686

Please sign in to comment.