@agilecustoms/envctl 1.4.1 → 1.6.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.
@@ -212,7 +212,7 @@ export class TerraformAdapter {
212
212
  tfVarName = '';
213
213
  }
214
214
  }
215
- console.log('Running: terraform plan -auto-approve', ...args, '\n');
215
+ console.log('Running: terraform plan', ...args, '\n');
216
216
  try {
217
217
  await this.cli.run('terraform', ['plan', ...args], out_scanner, in_scanner);
218
218
  }
@@ -234,7 +234,7 @@ export class TerraformAdapter {
234
234
  }
235
235
  }
236
236
  async apply(args, attemptNo = 1) {
237
- console.log('Running: terraform apply ', ...args, '\n');
237
+ console.log('Running: terraform apply', ...args, '\n');
238
238
  this.printTime();
239
239
  try {
240
240
  await this.cli.run('terraform', ['apply', ...args]);
@@ -66,10 +66,9 @@ export class EnvService extends BaseService {
66
66
  const env = await this.tryGetEnv(key);
67
67
  if (env) {
68
68
  this.checkKind(env);
69
- if (env.status === EnvStatus.Deleting) {
70
- throw new KnownException(`Env ${env.key} status is DELETING, please wait`);
71
- }
69
+ this.handleDeleteStatuses(env);
72
70
  }
71
+ await this.lockTerraform(env, env === null);
73
72
  await this.terraformAdapter.plan(env, tfArgs);
74
73
  }
75
74
  async createEphemeral(key) {
@@ -79,11 +78,13 @@ export class EnvService extends BaseService {
79
78
  async lockTerraform(env, newEnv = false) {
80
79
  console.log('Lock providers');
81
80
  const res = await this.terraformAdapter.lock(newEnv);
82
- if (res.lockFile) {
83
- env.lockFile = res.lockFile;
84
- }
85
- if (res.stateFile) {
86
- env.stateFile = res.stateFile;
81
+ if (env !== null) {
82
+ if (res.lockFile) {
83
+ env.lockFile = res.lockFile;
84
+ }
85
+ if (res.stateFile) {
86
+ env.stateFile = res.stateFile;
87
+ }
87
88
  }
88
89
  }
89
90
  async ensurePlan(env, args) {
@@ -106,6 +107,16 @@ export class EnvService extends BaseService {
106
107
  }
107
108
  return applyArgs;
108
109
  }
110
+ handleDeleteStatuses(env) {
111
+ if (env.status === EnvStatus.Deleting) {
112
+ throw new KnownException(`Env ${env.key} status is DELETING, please wait.\n
113
+ If it is DELETING more than 10 minutes, you can try to run 'envctl delete ${env.key} --force' to remove it`);
114
+ }
115
+ if (env.status === EnvStatus.DeleteError) {
116
+ throw new KnownException(`Env ${env.key} status is DELETE_ERROR, most likely lack of permissions.\n
117
+ Check logs with 'envctl logs', address the issue and re-run 'envctl delete ${env.key}'`);
118
+ }
119
+ }
109
120
  async deploy(tfArgs) {
110
121
  const key = this.terraformAdapter.getTerraformBackend().getKey();
111
122
  let env = await this.tryGetEnv(key);
@@ -121,10 +132,8 @@ export class EnvService extends BaseService {
121
132
  return;
122
133
  }
123
134
  this.checkKind(env);
135
+ this.handleDeleteStatuses(env);
124
136
  const status = env.status;
125
- if (status === EnvStatus.Deleting) {
126
- throw new KnownException(`Env ${env.key} status is DELETING, please wait`);
127
- }
128
137
  if (status === EnvStatus.Deploying || status === EnvStatus.Updating) {
129
138
  const answerYes = await this.cli.promptYesNo(`Env status is ${status}, likely due to an error from a previous run\n
130
139
  Do you want to proceed with deployment?`);
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": "1.4.1",
4
+ "version": "1.6.0",
5
5
  "author": "Alex Chekulaev",
6
6
  "type": "module",
7
7
  "engines": {
@@ -32,11 +32,10 @@
32
32
  "run-configure": "npm run run -- configure",
33
33
  "~": "",
34
34
  "run-core-init": " cd ../tt-core && terraform init -upgrade -backend-config=key=laxa1986 -reconfigure",
35
- "run-core-tfplan": "cd ../tt-core && terraform plan -out=.terraform/plan",
36
35
  "run-core-status": " npm run run -- status --cwd ../tt-core",
37
- "run-core-plan": " npm run run -- plan --cwd ../tt-core",
36
+ "run-core-plan": " npm run run -- plan --cwd ../tt-core -out=.terraform/plan",
37
+ "run-core-deployp": "npm run run -- deploy --cwd ../tt-core .terraform/plan",
38
38
  "run-core-deploy": " npm run run -- deploy --cwd ../tt-core -var=\"env_size=min\"",
39
- "run-core-deployp": "npm run run -- deploy .terraform/plan --cwd ../tt-core",
40
39
  "run-core-delete": " npm run run -- delete --cwd ../tt-core",
41
40
  "run-core-destroy": "npm run run -- destroy --cwd ../tt-core",
42
41
  "run-core-logs": " npm run run -- logs --cwd ../tt-core",