@agilecustoms/envctl 1.28.0 → 1.28.1

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)) {
@@ -296,7 +308,7 @@ export class TerraformAdapter {
296
308
  logger.debug('timeout(ms): ' + timeoutMs);
297
309
  logger.info('Running: terraform apply ' + args.join(' ') + '\n');
298
310
  try {
299
- await this.cli.run('terraform', ['apply', ...args], { timeoutMs, interactive: true });
311
+ await this.terraform(['apply', ...args], { timeoutMs, interactive: true });
300
312
  this.printTime();
301
313
  }
302
314
  catch (error) {
@@ -329,7 +341,7 @@ export class TerraformAdapter {
329
341
  };
330
342
  logger.info('Running: terraform destroy ' + args.join(' ') + '\n');
331
343
  try {
332
- await this.cli.run('terraform', ['destroy', ...args], { outScanner, interactive: true });
344
+ await this.terraform(['destroy', ...args], { outScanner, interactive: true });
333
345
  }
334
346
  catch (error) {
335
347
  if (!(error instanceof ProcessException)) {
@@ -373,6 +385,6 @@ export class TerraformAdapter {
373
385
  }
374
386
  async forceUnlock(id) {
375
387
  logger.info('Force unlocking state');
376
- await this.cli.run('terraform', ['force-unlock', '-force', id]);
388
+ await this.terraform(['force-unlock', '-force', id]);
377
389
  }
378
390
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agilecustoms/envctl",
3
- "version": "1.28.0",
3
+ "version": "1.28.1",
4
4
  "description": "node.js CLI client for manage environments",
5
5
  "keywords": [
6
6
  "terraform wrapper",