-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconfigure.ts
79 lines (59 loc) · 2.12 KB
/
configure.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
import { flags } from "@oclif/command"
import chalk from "chalk"
import BaseInfrastructureCommand from "../../BaseInfrastructureCommand"
import InfrastructureFactory from "../../lib/infrastructures/InfrastructureFactory"
import environmentsManager from "../../lib/environments"
/**
* Represents the "scaffold env:configure" command
* used to configure an environment.
*/
class EnvConfigure extends BaseInfrastructureCommand {
static args = [{
name: "environment",
required: true,
}]
static description = "configure passed environment"
static flags = {
help: flags.help({
char: "h",
}),
}
async run() {
const { args } = this.parse(EnvConfigure)
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 environmentToConfigure = args.environment as string
const environments = await environmentsManager.findAll(infrastructurePath)
if (!environments.all.includes(environmentToConfigure)) {
this.error(`"${chalk.bold(environmentToConfigure)}" environment not found.`)
}
if (environments.configured.includes(environmentToConfigure)) {
this.error(`"${chalk.bold(environmentToConfigure)}" environment already configured.`)
}
const cdktfPath = this.cdktfPath(infrastructurePath)
const terraformBinaryPath = BaseInfrastructureCommand.terraformBinaryPath()
const terraformPlanPath = await this.terraformPlanPath(infrastructurePath)
await environmentsManager.configure(
environmentToConfigure,
false,
infrastructure,
infrastructurePath,
this.configFilePath,
cdktfPath,
terraformBinaryPath,
terraformPlanPath
)
}
}
export default EnvConfigure