@@ -6,7 +6,7 @@ import * as fs from 'fs-extra';
66import { NonInteractiveIoHost } from './non-interactive-io-host' ;
77import type { ToolkitServices } from './private' ;
88import { assemblyFromSource } from './private' ;
9- import type { DeployResult } from './types' ;
9+ import type { DeployResult , DestroyResult } from './types' ;
1010import type { BootstrapEnvironments , BootstrapOptions , BootstrapResult , EnvironmentBootstrapResult } from '../actions/bootstrap' ;
1111import { BootstrapSource } from '../actions/bootstrap' ;
1212import { AssetBuildTime , type DeployOptions } from '../actions/deploy' ;
@@ -854,7 +854,7 @@ export class Toolkit extends CloudAssemblySourceBuilder {
854854 *
855855 * Destroys the selected Stacks.
856856 */
857- public async destroy ( cx : ICloudAssemblySource , options : DestroyOptions ) : Promise < void > {
857+ public async destroy ( cx : ICloudAssemblySource , options : DestroyOptions ) : Promise < DestroyResult > {
858858 const ioHelper = asIoHelper ( this . ioHost , 'destroy' ) ;
859859 const assembly = await assemblyFromSource ( ioHelper , cx ) ;
860860 return this . _destroy ( assembly , 'destroy' , options ) ;
@@ -863,18 +863,23 @@ export class Toolkit extends CloudAssemblySourceBuilder {
863863 /**
864864 * Helper to allow destroy being called as part of the deploy action.
865865 */
866- private async _destroy ( assembly : StackAssembly , action : 'deploy' | 'destroy' , options : DestroyOptions ) : Promise < void > {
866+ private async _destroy ( assembly : StackAssembly , action : 'deploy' | 'destroy' , options : DestroyOptions ) : Promise < DestroyResult > {
867867 const ioHelper = asIoHelper ( this . ioHost , action ) ;
868868 const synthSpan = await ioHelper . span ( SPAN . SYNTH_ASSEMBLY ) . begin ( { stacks : options . stacks } ) ;
869869 // The stacks will have been ordered for deployment, so reverse them for deletion.
870870 const stacks = ( await assembly . selectStacksV2 ( options . stacks ) ) . reversed ( ) ;
871871 await synthSpan . end ( ) ;
872872
873+ const ret : DestroyResult = {
874+ stacks : [ ] ,
875+ } ;
876+
873877 const motivation = 'Destroying stacks is an irreversible action' ;
874878 const question = `Are you sure you want to delete: ${ chalk . red ( stacks . hierarchicalIds . join ( ', ' ) ) } ` ;
875879 const confirmed = await ioHelper . requestResponse ( IO . CDK_TOOLKIT_I7010 . req ( question , { motivation } ) ) ;
876880 if ( ! confirmed ) {
877- return ioHelper . notify ( IO . CDK_TOOLKIT_E7010 . msg ( 'Aborted by user' ) ) ;
881+ await ioHelper . notify ( IO . CDK_TOOLKIT_E7010 . msg ( 'Aborted by user' ) ) ;
882+ return ret ;
878883 }
879884
880885 const destroySpan = await ioHelper . span ( SPAN . DESTROY_ACTION ) . begin ( {
@@ -890,18 +895,30 @@ export class Toolkit extends CloudAssemblySourceBuilder {
890895 stack,
891896 } ) ;
892897 const deployments = await this . deploymentsForAction ( action ) ;
893- await deployments . destroyStack ( {
898+ const result = await deployments . destroyStack ( {
894899 stack,
895900 deployName : stack . stackName ,
896901 roleArn : options . roleArn ,
897902 } ) ;
903+
904+ ret . stacks . push ( {
905+ environment : {
906+ account : stack . environment . account ,
907+ region : stack . environment . region ,
908+ } ,
909+ stackName : stack . stackName ,
910+ stackArn : result . stackArn ,
911+ } ) ;
912+
898913 await ioHelper . notify ( IO . CDK_TOOLKIT_I7900 . msg ( chalk . green ( `\n ✅ ${ chalk . blue ( stack . displayName ) } : ${ action } ed` ) , stack ) ) ;
899914 await singleDestroySpan . end ( ) ;
900915 } catch ( e : any ) {
901916 await ioHelper . notify ( IO . CDK_TOOLKIT_E7900 . msg ( `\n ❌ ${ chalk . blue ( stack . displayName ) } : ${ action } failed ${ e } ` , { error : e } ) ) ;
902917 throw e ;
903918 }
904919 }
920+
921+ return ret ;
905922 } finally {
906923 await destroySpan . end ( ) ;
907924 }
0 commit comments