@agilecustoms/envctl 1.28.0 → 1.28.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.
@@ -65,6 +65,18 @@ export class TerraformAdapter {
65
65
  return acc;
66
66
  }, new Map());
67
67
  }
68
+ async terraform(args, options = {}) {
69
+ try {
70
+ await this.cli.run('terraform', args, options);
71
+ }
72
+ catch (error) {
73
+ if (error instanceof ProcessException && error.code !== null && [-2, -4058].includes(error.code)) {
74
+ const msg = `terraform command failed with code ${error.code}. Perhaps terraform is not installed`;
75
+ throw new KnownException(`${msg}. Details:\n${error.message}`, { cause: error });
76
+ }
77
+ throw error;
78
+ }
79
+ }
68
80
  getBackend() {
69
81
  if (this.backend) {
70
82
  return this.backend;
@@ -159,7 +171,7 @@ export class TerraformAdapter {
159
171
  if (!linuxArm64) {
160
172
  logger.info('Lock providers');
161
173
  const vars = this.getVars(args);
162
- await this.cli.run('terraform', ['providers', 'lock', '-platform=linux_arm64', ...vars]);
174
+ await this.terraform(['providers', 'lock', '-platform=linux_arm64', ...vars]);
163
175
  }
164
176
  const fileContent = this.getLockFile();
165
177
  const config = this.localStateService.load();
@@ -232,7 +244,7 @@ export class TerraformAdapter {
232
244
  async init(args) {
233
245
  logger.info('Running: terraform init ' + args.join(' ') + '\n');
234
246
  try {
235
- await this.cli.run('terraform', ['init', ...args], { interactive: true });
247
+ await this.terraform(['init', ...args], { interactive: true });
236
248
  }
237
249
  catch (error) {
238
250
  if (!(error instanceof ProcessException)) {
@@ -248,7 +260,7 @@ export class TerraformAdapter {
248
260
  async _plan(args, attemptNo) {
249
261
  logger.info('Running: terraform plan ' + args.join(' ') + '\n');
250
262
  try {
251
- await this.cli.run('terraform', ['plan', ...args], { interactive: true });
263
+ await this.terraform(['plan', ...args], { interactive: true });
252
264
  }
253
265
  catch (error) {
254
266
  if (!(error instanceof ProcessException)) {
@@ -272,7 +284,6 @@ export class TerraformAdapter {
272
284
  if (noPlan) {
273
285
  args = this.tfArgs(env.key, args);
274
286
  }
275
- logger.info('Running: terraform apply ' + args.join(' ') + '\n');
276
287
  try {
277
288
  await this._apply(args, env.ttl, 1);
278
289
  }
@@ -296,7 +307,7 @@ export class TerraformAdapter {
296
307
  logger.debug('timeout(ms): ' + timeoutMs);
297
308
  logger.info('Running: terraform apply ' + args.join(' ') + '\n');
298
309
  try {
299
- await this.cli.run('terraform', ['apply', ...args], { timeoutMs, interactive: true });
310
+ await this.terraform(['apply', ...args], { timeoutMs, interactive: true });
300
311
  this.printTime();
301
312
  }
302
313
  catch (error) {
@@ -329,7 +340,7 @@ export class TerraformAdapter {
329
340
  };
330
341
  logger.info('Running: terraform destroy ' + args.join(' ') + '\n');
331
342
  try {
332
- await this.cli.run('terraform', ['destroy', ...args], { outScanner, interactive: true });
343
+ await this.terraform(['destroy', ...args], { outScanner, interactive: true });
333
344
  }
334
345
  catch (error) {
335
346
  if (!(error instanceof ProcessException)) {
@@ -373,6 +384,6 @@ export class TerraformAdapter {
373
384
  }
374
385
  async forceUnlock(id) {
375
386
  logger.info('Force unlocking state');
376
- await this.cli.run('terraform', ['force-unlock', '-force', id]);
387
+ await this.terraform(['force-unlock', '-force', id]);
377
388
  }
378
389
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agilecustoms/envctl",
3
- "version": "1.28.0",
3
+ "version": "1.28.2",
4
4
  "description": "node.js CLI client for manage environments",
5
5
  "keywords": [
6
6
  "terraform wrapper",