fix create/delete when there exists broken stacks
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
import { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu';
|
||||
|
||||
export type Stack = {
|
||||
name: string;
|
||||
status: string;
|
||||
drift_status: string;
|
||||
branch: string;
|
||||
updated: string;
|
||||
created: string;
|
||||
};
|
||||
|
||||
export const getTestStacksInfo = async (
|
||||
toolbox: GluegunMenuToolbox
|
||||
): Promise<Stack[]> => {
|
||||
const { strings, system } = toolbox;
|
||||
|
||||
const stacks = JSON.parse(
|
||||
strings.trim(await system.run(`aws cloudformation list-stacks`))
|
||||
);
|
||||
|
||||
const allStacks = await Promise.all(
|
||||
stacks.StackSummaries.map(async item => {
|
||||
if (
|
||||
item.StackName.indexOf('photowall-test-') > -1 &&
|
||||
[
|
||||
'CREATE_COMPLETE',
|
||||
'UPDATE_COMPLETE',
|
||||
'UPDATE_IN_PROGRESS',
|
||||
'UPDATE_FAILED',
|
||||
'CREATE_FAILED',
|
||||
'CREATE_IN_PROGRESS',
|
||||
'ROLLBACK_COMPLETE'
|
||||
].includes(item.StackStatus)
|
||||
) {
|
||||
try {
|
||||
const pipeline = JSON.parse(
|
||||
strings.trim(
|
||||
await system.run(
|
||||
`aws codepipeline get-pipeline --name ${item.StackName}Pipeline`
|
||||
)
|
||||
)
|
||||
);
|
||||
const sourceStage = pipeline.pipeline.stages.filter(stage => {
|
||||
return stage.name === 'Source';
|
||||
});
|
||||
const branch =
|
||||
sourceStage[0].actions[0].configuration.Branch ??
|
||||
sourceStage[0].actions[0].configuration.BranchName;
|
||||
const lastUpdated = pipeline.metadata.updated;
|
||||
return {
|
||||
name: item.StackName,
|
||||
status: item.StackStatus,
|
||||
drift_status: item.DriftInformation.StackDriftStatus,
|
||||
branch: branch,
|
||||
updated: lastUpdated,
|
||||
created: item.CreationTime
|
||||
};
|
||||
} catch (e) {
|
||||
return {
|
||||
name: item.StackName,
|
||||
status: item.StackStatus,
|
||||
drift_status: '',
|
||||
branch: '',
|
||||
updated: '',
|
||||
created: item.CreationTime
|
||||
};
|
||||
}
|
||||
}
|
||||
return Promise.resolve(null);
|
||||
})
|
||||
) as Stack[] | null;
|
||||
return allStacks.filter(Boolean);
|
||||
};
|
||||
Reference in New Issue
Block a user