-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathall.ts
97 lines (78 loc) · 2.16 KB
/
all.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import execa from "execa"
import { flags } from "@oclif/command"
import BaseInfrastructureCommand from "../../BaseInfrastructureCommand"
import InfrastructureFactory from "../../lib/infrastructures/InfrastructureFactory"
/**
* Represents the "scaffold terraform:{command}" command
* used to forward commands to the Terraform binary.
*/
class TerraformAll extends BaseInfrastructureCommand {
static aliases = [
"apply",
"console",
"destroy",
"env",
"fmt",
"get",
"graph",
"import",
"init",
"login",
"logout",
"output",
"plan",
"providers",
"refresh",
"show",
"taint",
"untaint",
"validate",
"version",
"workspace",
"0.12upgrade",
"0.13upgrade",
"debug",
"force-unlock",
"push",
"state",
].map(alias => `terraform:${alias}`)
static args = []
static description = "forward commands to the Terraform binary"
static flags = {
help: flags.help({
char: "h",
}),
}
async run() {
await this.ensureAllRequirements()
const infrastructurePath = await this.infrastructurePath()
if (!infrastructurePath) {
this.error("No infrastructures found.")
}
const infrastructurePackage = await this.infrastructurePackage(infrastructurePath)
if (!infrastructurePackage) {
this.error("Invalid scaffold.json file.")
}
const infrastructure = InfrastructureFactory.infrastructure(infrastructurePackage.type)
if (!infrastructure) {
this.error("Unknown infrastructure.")
}
const terraformPlanPath = await this.terraformPlanPath(infrastructurePath)
const terraformPath = BaseInfrastructureCommand.terraformBinaryPath()
// Remove ["node", "{path}"]
const passedArgs = process.argv.slice(2)
passedArgs[0] = passedArgs[0].replace(/^terraform:/, "")
const terraformCommand = execa(terraformPath, passedArgs, {
cwd: terraformPlanPath,
})
terraformCommand.stderr.pipe(process.stderr)
terraformCommand.stdout.pipe(process.stdout)
process.stdin.pipe(terraformCommand.stdin)
try {
await terraformCommand
} catch (error) {
this.exit(1)
}
}
}
export default TerraformAll