@agilecustoms/envctl 0.33.0 → 0.35.0

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.
@@ -42,6 +42,7 @@ export class EnvApiClient {
42
42
  env.status = status;
43
43
  }
44
44
  async delete(env) {
45
+ console.log('Sending delete command');
45
46
  let result;
46
47
  try {
47
48
  result = await this.httpClient.fetch(`/ci/env/${env.key}`, {
@@ -55,6 +56,6 @@ export class EnvApiClient {
55
56
  throw error;
56
57
  }
57
58
  env.status = EnvStatus.Deleting;
58
- return result.statusText;
59
+ console.log(result.statusText);
59
60
  }
60
61
  }
@@ -54,35 +54,24 @@ export class EnvCtl {
54
54
  }
55
55
  return env;
56
56
  }
57
- checkInput(env, cwd) {
57
+ checkKind(env, cwd) {
58
58
  if (env.ephemeral)
59
59
  return;
60
60
  if (env.kind) {
61
61
  const kind = this.cliHelper.getKind(cwd);
62
62
  if (kind !== env.kind) {
63
- throw new KnownException(`Can not change env kind ${env.kind} -> ${kind}`);
63
+ throw new KnownException(`Env ${env.key} kind (dir-name): ${env.kind} - make sure you run this command from the same directory`);
64
64
  }
65
65
  }
66
66
  }
67
- checkStatus(env, availableStatuses = [EnvStatus.Init, EnvStatus.Deploying, EnvStatus.Active, EnvStatus.Updating]) {
68
- if (availableStatuses.includes(env.status)) {
69
- return;
70
- }
71
- if (env.status === EnvStatus.Deleting) {
72
- throw new KnownException(`Env ${env.key} status is DELETING, please wait`);
73
- }
74
- throw new KnownException(`Env ${env.key} status is ${env.status}, can not run this command`);
75
- }
76
67
  async plan(tfArgs, cwd) {
77
68
  const key = this.terraformAdapter.getTerraformBackend(cwd).getKey();
78
69
  const env = await this.tryGetEnv(key);
79
70
  let vars = undefined;
80
71
  if (env) {
81
- this.checkInput(env, cwd);
82
- this.checkStatus(env);
83
- await this.promptUnlock(env);
84
- if (env.status !== EnvStatus.Active) {
85
- throw new KnownException(`Env ${env.key} status is ${env.status}, can not run plan`);
72
+ this.checkKind(env, cwd);
73
+ if (env.status === EnvStatus.Deleting) {
74
+ throw new KnownException(`Env ${env.key} status is DELETING, please wait`);
86
75
  }
87
76
  vars = env.vars;
88
77
  }
@@ -113,26 +102,30 @@ export class EnvCtl {
113
102
  await this.lockTerraform(createEnv, cwd);
114
103
  console.log('Creating env metadata');
115
104
  env = await this.envApi.create(createEnv);
105
+ await this.runDeploy(env, key, tfArgs, cwd);
106
+ return;
116
107
  }
117
- else {
118
- this.checkInput(env, cwd);
119
- this.checkStatus(env);
120
- await this.lockTerraform(env, cwd);
121
- if (env.status === EnvStatus.Init) {
108
+ this.checkKind(env, cwd);
109
+ switch (env.status) {
110
+ case EnvStatus.Init:
111
+ case EnvStatus.Active:
112
+ if (env.status === EnvStatus.Active) {
113
+ console.log('Env status is ACTIVE\nWill lock for update and run terraform apply (to update resources)');
114
+ }
115
+ await this.lockTerraform(env, cwd);
122
116
  await this.envApi.lockForUpdate(env);
123
- }
124
- else if (env.status == EnvStatus.Updating) {
117
+ break;
118
+ case EnvStatus.Deploying:
119
+ case EnvStatus.Updating:
125
120
  const answerYes = await this.cliHelper.promptYesNo(`Env status is ${env.status}, likely due to an error from a previous run\n
126
121
  Do you want to proceed with deployment?`);
127
122
  if (!answerYes) {
128
123
  console.log('Aborting deployment');
129
124
  return;
130
125
  }
131
- }
132
- else if (env.status === EnvStatus.Active) {
133
- console.log('Env status is ACTIVE\nWill lock for update and run terraform apply (to update resources)');
134
- await this.envApi.lockForUpdate(env);
135
- }
126
+ break;
127
+ case EnvStatus.Deleting:
128
+ throw new KnownException(`Env ${env.key} status is DELETING, please wait`);
136
129
  }
137
130
  await this.runDeploy(env, key, tfArgs, cwd);
138
131
  }
@@ -158,49 +151,42 @@ export class EnvCtl {
158
151
  async delete(force, key, cwd) {
159
152
  key = this.getKey(key, cwd);
160
153
  const env = await this.get(key);
161
- if (!force) {
162
- this.checkStatus(env);
163
- if (env.status === EnvStatus.Init) {
164
- await this.envApi.delete(env);
165
- console.log(`Env ${env.key} is deleted`);
166
- return;
167
- }
168
- const kind = this.cliHelper.getKind(cwd);
169
- if (env.kind && env.kind !== kind) {
170
- const answerYes = await this.cliHelper.promptYesNo(`Env ${env.key} kind (dir-name): ${env.kind}\n`
171
- + 'You\'re deleting env deployed from different dir\n'
172
- + 'Do you want to proceed?');
173
- if (!answerYes) {
174
- console.log('Aborting deletion');
175
- return;
176
- }
177
- }
178
- await this.promptUnlock(env);
179
- if (env.status !== EnvStatus.Active) {
154
+ if (env.status === EnvStatus.Init) {
155
+ await this.envApi.delete(env);
156
+ return;
157
+ }
158
+ if (force) {
159
+ await this.envApi.delete(env);
160
+ return;
161
+ }
162
+ if (env.status === EnvStatus.Deleting) {
163
+ throw new KnownException(`Env ${env.key} status is DELETING, please wait or re-run with --force`);
164
+ }
165
+ const kind = this.cliHelper.getKind(cwd);
166
+ if (env.kind && env.kind !== kind) {
167
+ const answerYes = await this.cliHelper.promptYesNo(`Env ${env.key} kind (dir-name): ${env.kind}\n`
168
+ + 'You\'re deleting env deployed from different dir\n'
169
+ + 'Do you want to proceed?');
170
+ if (!answerYes) {
171
+ console.log('Aborting deletion');
180
172
  return;
181
173
  }
182
174
  }
183
- console.log('Sending delete command');
184
- const message = await this.envApi.delete(env);
185
- console.log(message);
175
+ await this.envApi.delete(env);
186
176
  }
187
177
  async destroy(tfArgs, force, cwd) {
188
178
  const key = this.terraformAdapter.getTerraformBackend(cwd).getKey();
189
179
  const env = await this.get(key);
190
180
  if (env.status === EnvStatus.Init) {
191
- console.log(`Env ${env.key} has no resources, nothing to destroy, call 'delete' command instead`);
181
+ console.log(`Env ${env.key} status is INIT - no resources, nothing to destroy, just deleting metadata`);
182
+ await this.envApi.delete(env);
192
183
  return;
193
184
  }
194
185
  if (!force) {
195
- this.checkStatus(env);
196
- const kind = this.cliHelper.getKind(cwd);
197
- if (env.kind && env.kind !== kind) {
198
- throw new KnownException(`Env ${env.key} kind (dir-name): ${env.kind} - make sure you run destroy from the same directory`);
199
- }
200
- await this.promptUnlock(env, [EnvStatus.Deploying]);
201
- if (env.status === EnvStatus.Deploying) {
202
- return;
186
+ if (env.status === EnvStatus.Deleting) {
187
+ throw new KnownException(`Env ${env.key} status is DELETING, please wait or re-run with --force`);
203
188
  }
189
+ this.checkKind(env, cwd);
204
190
  }
205
191
  if (env.status === EnvStatus.Active) {
206
192
  console.log('Lock env to run destroy');
@@ -210,9 +196,6 @@ export class EnvCtl {
210
196
  const envTerraform = { key, ephemeral, args: tfArgs, vars };
211
197
  console.log('Destroying env resources');
212
198
  await this.terraformAdapter.destroy(envTerraform, force, cwd);
213
- console.log('Unlock env');
214
- await this.envApi.activate(env);
215
- console.log(`Schedule env ${env.key} metadata deletion`);
216
199
  await this.envApi.delete(env);
217
200
  console.log('Please wait for ~15 sec before you can create env with same name');
218
201
  }
@@ -225,13 +208,4 @@ export class EnvCtl {
225
208
  console.log(`Env status: ${env.status}`);
226
209
  return env;
227
210
  }
228
- async promptUnlock(env, statuses = [EnvStatus.Deploying, EnvStatus.Updating]) {
229
- if (statuses.includes(env.status)) {
230
- const answerYes = await this.cliHelper.promptYesNo(`Env status is ${env.status}, likely to be an error from a previous run\n`
231
- + 'Do you want to unlock it?');
232
- if (answerYes) {
233
- await this.envApi.activate(env);
234
- }
235
- }
236
- }
237
211
  }
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.33.0",
4
+ "version": "0.35.0",
5
5
  "author": "Alex Chekulaev",
6
6
  "type": "module",
7
7
  "bin": {
@@ -29,12 +29,19 @@
29
29
  "run-version": " tsc --sourceMap true && npm run run -- --version",
30
30
  "run-configure": "tsc --sourceMap true && npm run run -- configure",
31
31
  "~": "",
32
- "run-init": "cd ../tt-core && terraform init -upgrade -backend-config=key=laxa1986",
33
- "run-status": " tsc --sourceMap true && npm run run -- status --cwd ../tt-core",
34
- "run-plan": " tsc --sourceMap true && npm run run -- plan --cwd ../tt-core",
35
- "run-deploy": " tsc --sourceMap true && npm run run -- deploy --cwd ../tt-core -var=\"env_size=min\"",
36
- "run-delete": " tsc --sourceMap true && npm run run -- delete --cwd ../tt-core",
37
- "run-destroy": "tsc --sourceMap true && npm run run -- destroy --cwd ../tt-core",
32
+ "run-core-init": "cd ../tt-core && terraform init -upgrade -backend-config=key=laxa1986",
33
+ "run-core-status": " tsc --sourceMap true && npm run run -- status --cwd ../tt-core",
34
+ "run-core-plan": " tsc --sourceMap true && npm run run -- plan --cwd ../tt-core",
35
+ "run-core-deploy": " tsc --sourceMap true && npm run run -- deploy --cwd ../tt-core -var=\"env_size=min\"",
36
+ "run-core-delete": " tsc --sourceMap true && npm run run -- delete --cwd ../tt-core",
37
+ "run-core-destroy": "tsc --sourceMap true && npm run run -- destroy --cwd ../tt-core",
38
+ "*": "",
39
+ "run-init": "cd ../tt-gitops && terraform init -upgrade -backend-config=key=laxa1986 -reconfigure",
40
+ "run-status": " tsc --sourceMap true && npm run run -- status --cwd ../tt-gitops",
41
+ "run-plan": " tsc --sourceMap true && AWS_PROFILE=ac-tt-dev-deployer npm run run -- plan --cwd ../tt-gitops -var=\"env_size=min\" -var-file=versions.tfvars",
42
+ "run-deploy": " tsc --sourceMap true && AWS_PROFILE=ac-tt-dev-deployer npm run run -- deploy --cwd ../tt-gitops -var=\"env_size=min\" -var-file=versions.tfvars",
43
+ "run-delete": " tsc --sourceMap true && npm run run -- delete --cwd ../tt-gitops",
44
+ "run-destroy": "tsc --sourceMap true && AWS_PROFILE=ac-tt-dev-destroyer npm run run -- destroy --cwd ../tt-gitops -var=\"env_size=min\" -var-file=versions.tfvars",
38
45
  "-": "",
39
46
  "run-ephemeral-create": " tsc --sourceMap true && npm run run -- create-ephemeral --key test",
40
47
  "run-ephemeral-init": "cd ../tt-gitops && terraform init -upgrade -backend-config=key=test -reconfigure",