@@ -7,7 +7,7 @@ import * as uuid from 'uuid';
77import { NonInteractiveIoHost } from './non-interactive-io-host' ;
88import type { ToolkitServices } from './private' ;
99import { assemblyFromSource } from './private' ;
10- import type { DeployResult } from './types' ;
10+ import type { DeployResult , DestroyResult } from './types' ;
1111import type { BootstrapEnvironments , BootstrapOptions , BootstrapResult , EnvironmentBootstrapResult } from '../actions/bootstrap' ;
1212import { BootstrapSource } from '../actions/bootstrap' ;
1313import { AssetBuildTime , type DeployOptions } from '../actions/deploy' ;
@@ -923,7 +923,7 @@ export class Toolkit extends CloudAssemblySourceBuilder {
923923 *
924924 * Destroys the selected Stacks.
925925 */
926- public async destroy ( cx : ICloudAssemblySource , options : DestroyOptions ) : Promise < void > {
926+ public async destroy ( cx : ICloudAssemblySource , options : DestroyOptions ) : Promise < DestroyResult > {
927927 const ioHelper = asIoHelper ( this . ioHost , 'destroy' ) ;
928928 const assembly = await assemblyFromSource ( ioHelper , cx ) ;
929929 return this . _destroy ( assembly , 'destroy' , options ) ;
@@ -932,18 +932,23 @@ export class Toolkit extends CloudAssemblySourceBuilder {
932932 /**
933933 * Helper to allow destroy being called as part of the deploy action.
934934 */
935- private async _destroy ( assembly : StackAssembly , action : 'deploy' | 'destroy' , options : DestroyOptions ) : Promise < void > {
935+ private async _destroy ( assembly : StackAssembly , action : 'deploy' | 'destroy' , options : DestroyOptions ) : Promise < DestroyResult > {
936936 const ioHelper = asIoHelper ( this . ioHost , action ) ;
937937 const synthSpan = await ioHelper . span ( SPAN . SYNTH_ASSEMBLY ) . begin ( { stacks : options . stacks } ) ;
938938 // The stacks will have been ordered for deployment, so reverse them for deletion.
939939 const stacks = ( await assembly . selectStacksV2 ( options . stacks ) ) . reversed ( ) ;
940940 await synthSpan . end ( ) ;
941941
942+ const ret : DestroyResult = {
943+ stacks : [ ] ,
944+ } ;
945+
942946 const motivation = 'Destroying stacks is an irreversible action' ;
943947 const question = `Are you sure you want to delete: ${ chalk . red ( stacks . hierarchicalIds . join ( ', ' ) ) } ` ;
944948 const confirmed = await ioHelper . requestResponse ( IO . CDK_TOOLKIT_I7010 . req ( question , { motivation } ) ) ;
945949 if ( ! confirmed ) {
946- return ioHelper . notify ( IO . CDK_TOOLKIT_E7010 . msg ( 'Aborted by user' ) ) ;
950+ await ioHelper . notify ( IO . CDK_TOOLKIT_E7010 . msg ( 'Aborted by user' ) ) ;
951+ return ret ;
947952 }
948953
949954 const destroySpan = await ioHelper . span ( SPAN . DESTROY_ACTION ) . begin ( {
@@ -959,18 +964,30 @@ export class Toolkit extends CloudAssemblySourceBuilder {
959964 stack,
960965 } ) ;
961966 const deployments = await this . deploymentsForAction ( action ) ;
962- await deployments . destroyStack ( {
967+ const result = await deployments . destroyStack ( {
963968 stack,
964969 deployName : stack . stackName ,
965970 roleArn : options . roleArn ,
966971 } ) ;
972+
973+ ret . stacks . push ( {
974+ environment : {
975+ account : stack . environment . account ,
976+ region : stack . environment . region ,
977+ } ,
978+ stackName : stack . stackName ,
979+ stackArn : result . stackArn ,
980+ } ) ;
981+
967982 await ioHelper . notify ( IO . CDK_TOOLKIT_I7900 . msg ( chalk . green ( `\n ✅ ${ chalk . blue ( stack . displayName ) } : ${ action } ed` ) , stack ) ) ;
968983 await singleDestroySpan . end ( ) ;
969984 } catch ( e : any ) {
970985 await ioHelper . notify ( IO . CDK_TOOLKIT_E7900 . msg ( `\n ❌ ${ chalk . blue ( stack . displayName ) } : ${ action } failed ${ e } ` , { error : e } ) ) ;
971986 throw e ;
972987 }
973988 }
989+
990+ return ret ;
974991 } finally {
975992 await destroySpan . end ( ) ;
976993 }
0 commit comments