-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
42 lines (34 loc) · 942 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { exec } from 'child_process';
class Terraform {
directory: string;
constructor(directory: string) {
this.directory = directory;
}
run(command: string): Promise<string> {
return new Promise((resolve, reject) => {
exec(`terraform ${command}`, { cwd: this.directory }, (error, stdout, stderr) => {
if (error) {
console.log(error);
reject(stderr);
} else {
resolve(stdout);
}
});
});
}
init(): Promise<string> {
return this.run('init');
}
apply(autoApprove: boolean = true): Promise<string> {
const flag = autoApprove ? '-auto-approve' : '';
return this.run(`apply ${flag}`);
}
plan(): Promise<string> {
return this.run('plan');
}
destroy(autoApprove: boolean = true): Promise<string> {
const flag = autoApprove ? '-auto-approve' : '';
return this.run(`destroy ${flag}`);
}
}
export default Terraform;