@@ -6,7 +6,7 @@ const kebabcaseKeys = require('kebabcase-keys');
6
6
const timestring = require ( 'timestring' ) ;
7
7
const winston = require ( 'winston' ) ;
8
8
9
- const { randid, sleep } = require ( '../../../src/utils' ) ;
9
+ const { exec , randid, sleep } = require ( '../../../src/utils' ) ;
10
10
const tf = require ( '../../../src/terraform' ) ;
11
11
12
12
let cml ;
@@ -23,15 +23,7 @@ const shutdown = async (opts) => {
23
23
RUNNER_SHUTTING_DOWN = true ;
24
24
25
25
const { error, cloud } = opts ;
26
- const {
27
- name,
28
- workdir = '' ,
29
- tfResource,
30
- noRetry,
31
- reason,
32
- destroyDelay
33
- } = opts ;
34
- const tfPath = workdir ;
26
+ const { name, tfResource, noRetry, reason, destroyDelay } = opts ;
35
27
36
28
const unregisterRunner = async ( ) => {
37
29
if ( ! RUNNER ) return ;
@@ -63,16 +55,22 @@ const shutdown = async (opts) => {
63
55
}
64
56
} ;
65
57
66
- const destroyTerraform = async ( ) => {
58
+ const destroyLeo = async ( ) => {
67
59
if ( ! tfResource ) return ;
68
60
69
61
winston . info ( `Waiting ${ destroyDelay } seconds to destroy` ) ;
70
62
await sleep ( destroyDelay ) ;
71
63
64
+ const { cloud, id, region } = JSON . parse (
65
+ Buffer . from ( tfResource , 'base64' ) . toString ( 'utf-8' )
66
+ ) . instances [ 0 ] . attributes ;
67
+
72
68
try {
73
- winston . debug ( await tf . destroy ( { dir : tfPath } ) ) ;
69
+ return await exec (
70
+ `leo destroy-runner --cloud=${ cloud } --region=${ region } ${ id } `
71
+ ) ;
74
72
} catch ( err ) {
75
- winston . error ( `\tFailed destroying terraform : ${ err . message } ` ) ;
73
+ winston . error ( `\tFailed destroying with LEO : ${ err . message } ` ) ;
76
74
}
77
75
} ;
78
76
@@ -85,7 +83,7 @@ const shutdown = async (opts) => {
85
83
}
86
84
}
87
85
88
- await destroyTerraform ( ) ;
86
+ await destroyLeo ( ) ;
89
87
90
88
if ( error ) throw error ;
91
89
0 commit comments