@agilecustoms/envctl 0.18.0 → 0.18.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -26,7 +26,7 @@ export class ProcessRunner {
26
26
  for (const line of lines) {
27
27
  if (scanner)
28
28
  scanner(line);
29
- console.log(`> ${line}`);
29
+ console.log(line);
30
30
  }
31
31
  if (buffer.includes('Enter a value:')) {
32
32
  console.log(buffer);
@@ -41,7 +41,7 @@ export class ProcessRunner {
41
41
  child.on('close', (code) => {
42
42
  if (scanner)
43
43
  scanner(buffer);
44
- console.log(`> ${buffer}`);
44
+ console.log(buffer);
45
45
  if (code === 0) {
46
46
  if (errorBuffer) {
47
47
  console.warn('Process completed successfully, but there were errors:\n' + errorBuffer);
@@ -48,6 +48,7 @@ export class TerraformAdapter {
48
48
  `-var=owner=${env.owner}`,
49
49
  `-var=env_size=${env.size}`,
50
50
  `-var=env_type=${env.type}`,
51
+ `-var=ephemeral=${env.ephemeral}`,
51
52
  ...tfArgs
52
53
  ];
53
54
  }
@@ -8,11 +8,12 @@ export function deleteIt(program) {
8
8
  .description('Delete a development environment')
9
9
  .option('--project <project>', _keys.PROJECT)
10
10
  .option('--env <env>', _keys.ENV)
11
+ .option('--force', 'Force deletion without confirmation')
11
12
  .option('--cwd <cwd>', _keys.CWD)
12
13
  .action(wrap(handler));
13
14
  }
14
15
  async function handler(options) {
15
- const { project, env, cwd } = options;
16
+ const { project, env, force, cwd } = options;
16
17
  const envName = cliHelper.ensureEnv(env);
17
- await envCtl.delete(project, envName, cwd);
18
+ await envCtl.delete(project, envName, Boolean(force), cwd);
18
19
  }
@@ -21,7 +21,7 @@ export class EnvCtl {
21
21
  console.log(`Env ${key} does not exist`);
22
22
  return;
23
23
  }
24
- const kind = this.cliHelper.ensureKind(undefined, cwd);
24
+ const kind = env.kind ? this.cliHelper.ensureKind(undefined, cwd) : undefined;
25
25
  console.log(`Env ${key} status: ${env.status}`);
26
26
  if (env.kind && env.kind !== kind) {
27
27
  console.warn(`Env ${key} kind (dir-name): ${env.kind} - looks like this env was deployed from a different directory`);
@@ -47,9 +47,6 @@ export class EnvCtl {
47
47
  return { envName, owner, key, env };
48
48
  }
49
49
  checkInput(envName, env, input, cwd) {
50
- if (env.ephemeral) {
51
- throw new KnownException(`Attempted to convert ephemeral env to non-ephemeral`);
52
- }
53
50
  if (input.owner && env.owner !== input.owner) {
54
51
  throw new KnownException(`Can not change env owner ${env.owner} -> ${input.owner}`);
55
52
  }
@@ -87,17 +84,19 @@ export class EnvCtl {
87
84
  const { envName, owner, key, env } = await this.tryGetEnv(input);
88
85
  if (env == null) {
89
86
  const envInput = await this.cliHelper.parseEnvInput(input, envName, owner, cwd);
87
+ const envTerraform = { ...envInput, ephemeral: false };
90
88
  await this.terraformAdapter.init(key, cwd);
91
- await this.terraformAdapter.plan(envInput, tfArgs, cwd);
89
+ await this.terraformAdapter.plan(envTerraform, tfArgs, cwd);
92
90
  return;
93
91
  }
94
92
  const envInput = this.checkInput(envName, env, input, cwd);
93
+ const envTerraform = { ...envInput, ephemeral: false };
95
94
  this.checkStatus(env);
96
95
  await this.promptUnlock(env);
97
96
  if (env.status !== EnvStatus.Active) {
98
97
  throw new KnownException(`Env ${env.key} status is ${env.status}, can not run plan`);
99
98
  }
100
- await this.terraformAdapter.plan(envInput, tfArgs, cwd);
99
+ await this.terraformAdapter.plan(envTerraform, tfArgs, cwd);
101
100
  }
102
101
  async createEphemeral(project, envName, owner, size, type) {
103
102
  const key = this.key(project, envName);
@@ -121,7 +120,7 @@ export class EnvCtl {
121
120
  }
122
121
  this.checkInput(envName, env, input, cwd);
123
122
  this.checkStatus(env);
124
- if (env.status == EnvStatus.Creating || env.status == EnvStatus.Updating) {
123
+ if (env.status == EnvStatus.Updating) {
125
124
  const answerYes = await this.cliHelper.promptYesNo(`Env status is ${env.status}, likely to be an error from a previous run\n`
126
125
  + 'Do you want to proceed with deployment?');
127
126
  if (!answerYes) {
@@ -137,8 +136,8 @@ export class EnvCtl {
137
136
  }
138
137
  async runDeploy(env, envName, tfArgs, cwd) {
139
138
  console.log('Deploying resources');
140
- const { owner, size, type } = env;
141
- const envTf = { owner, size, type, env: envName };
139
+ const { owner, size, type, ephemeral } = env;
140
+ const envTf = { owner, size, type, ephemeral, env: envName };
142
141
  try {
143
142
  await this.terraformAdapter.apply(envTf, tfArgs, cwd);
144
143
  }
@@ -154,24 +153,33 @@ export class EnvCtl {
154
153
  console.log('Activating env (to finish creation)');
155
154
  await this.envApi.activate(env);
156
155
  }
157
- async delete(project, envName, cwd) {
156
+ async delete(project, envName, force, cwd) {
158
157
  const env = await this.get(project, envName);
159
158
  this.checkStatus(env);
160
- const kind = this.cliHelper.ensureKind(undefined, cwd);
161
- if (env.kind && env.kind !== kind) {
162
- const answerYes = await this.cliHelper.promptYesNo(`Env ${env.key} kind (dir-name): ${env.kind}\n`
163
- + 'You\'re deleting env deployed from different dir\n'
164
- + 'Do you want to proceed?');
165
- if (!answerYes) {
166
- console.log('Aborting deletion');
167
- return;
159
+ if (force) {
160
+ console.log('Force deletion');
161
+ if (env.status !== EnvStatus.Active) {
162
+ console.log(`Env status is ${env.status}, will unlock it`);
163
+ await this.envApi.activate(env);
168
164
  }
169
165
  }
170
- await this.promptUnlock(env);
171
- if (env.status !== EnvStatus.Active) {
172
- return;
166
+ else {
167
+ const kind = this.cliHelper.ensureKind(undefined, cwd);
168
+ if (env.kind && env.kind !== kind) {
169
+ const answerYes = await this.cliHelper.promptYesNo(`Env ${env.key} kind (dir-name): ${env.kind}\n`
170
+ + 'You\'re deleting env deployed from different dir\n'
171
+ + 'Do you want to proceed?');
172
+ if (!answerYes) {
173
+ console.log('Aborting deletion');
174
+ return;
175
+ }
176
+ }
177
+ await this.promptUnlock(env);
178
+ if (env.status !== EnvStatus.Active) {
179
+ return;
180
+ }
181
+ console.log('Deleting env');
173
182
  }
174
- console.log('Deleting env');
175
183
  const statusMessage = await this.envApi.delete(env);
176
184
  console.log(statusMessage);
177
185
  }
@@ -187,8 +195,8 @@ export class EnvCtl {
187
195
  console.log('Lock env to run destroy');
188
196
  await this.envApi.lockForUpdate(env);
189
197
  }
190
- const { owner, size, type } = env;
191
- const tfEnv = { owner, size, type, env: envName };
198
+ const { owner, size, type, ephemeral } = env;
199
+ const tfEnv = { owner, size, type, ephemeral, env: envName };
192
200
  console.log('Destroying env resources');
193
201
  await this.terraformAdapter.destroy(tfEnv, tfArgs, cwd);
194
202
  console.log('Unlock env');
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@agilecustoms/envctl",
3
3
  "description": "node.js CLI client for manage environments",
4
- "version": "0.18.0",
4
+ "version": "0.18.2",
5
5
  "author": "Alex Chekulaev",
6
6
  "type": "module",
7
7
  "bin": {
@@ -28,12 +28,15 @@
28
28
  "run-version": "tsc --sourceMap true && npm run run -- --version",
29
29
  "run-configure": "tsc --sourceMap true && npm run run -- configure",
30
30
  "run-status": "tsc --sourceMap true && npm run run -- status --cwd ../tt-core",
31
- "run-init": "tsc --sourceMap true && npm run run -- init --cwd ../tt-core",
32
31
  "run-plan": "tsc --sourceMap true && npm run run -- plan --size min --cwd ../tt-core",
33
32
  "run-deploy": "tsc --sourceMap true && npm run run -- deploy --size min --cwd ../tt-core",
34
33
  "run-delete": "tsc --sourceMap true && npm run run -- delete --cwd ../tt-core",
35
34
  "run-destroy": "tsc --sourceMap true && npm run run -- destroy --cwd ../tt-core",
36
- "run-api-create-ephemeral": "tsc --sourceMap true && npm run run -- api-create-ephemeral --env laxa1986 --owner laxa1986 --size min --type dev"
35
+ "run-api-status": "tsc --sourceMap true && npm run run -- status --env laxa1986",
36
+ "run-api-create-ephemeral": "tsc --sourceMap true && npm run run -- api-create-ephemeral --env laxa1986 --owner laxa1986 --size min --type dev",
37
+ "run-api-init": "tsc --sourceMap true && npm run run -- init --env laxa1986 --cwd ../tt-gitops",
38
+ "run-api-deploy": "tsc --sourceMap true && npm run run -- deploy --env laxa1986 -var-file=versions.tfvars --cwd ../tt-gitops",
39
+ "run-api-delete": "tsc --sourceMap true && npm run run -- delete --force --cwd ../tt-gitops"
37
40
  },
38
41
  "dependencies": {
39
42
  "@aws-sdk/client-sts": "^3.716.0",