@agilecustoms/envctl 0.25.0 → 0.26.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.
@@ -22,50 +22,6 @@ export class TerraformAdapter {
22
22
  });
23
23
  console.log(`\nTime EST: ${est}, UTC: ${utc}\n`);
24
24
  }
25
- async init(key, cwd, upgrade = false) {
26
- let accAlias = '';
27
- const accAliasScanner = (line) => {
28
- accAlias = line;
29
- };
30
- await this.processRunner.runScript('get-acc-alias.sh', [], cwd, accAliasScanner);
31
- console.log('Run terraform init to download providers, this doesn\'t create any resources in AWS even S3 object');
32
- let emptyDir = false;
33
- const scanner = (line) => {
34
- if (line.includes('Terraform initialized in an empty directory!')) {
35
- emptyDir = true;
36
- }
37
- };
38
- const bucket = `agilecustoms-${accAlias}-tf-state`;
39
- const args = [
40
- 'init',
41
- '-reconfigure',
42
- `-backend-config=bucket=${bucket}`,
43
- `-backend-config=key=${key}`
44
- ];
45
- if (upgrade) {
46
- args.push('-upgrade');
47
- }
48
- this.printTime();
49
- try {
50
- await this.processRunner.run('terraform', args, cwd, scanner);
51
- this.printTime();
52
- }
53
- catch (error) {
54
- if (error instanceof ProcessException) {
55
- if (!upgrade && error.message.includes('Failed to query available provider packages')) {
56
- args.push('-upgrade');
57
- await this.processRunner.run('terraform', args, cwd);
58
- this.printTime();
59
- return;
60
- }
61
- throw new KnownException(`terraform init failed with code ${error.code}:\n${error.message}`, { cause: error });
62
- }
63
- throw error;
64
- }
65
- if (emptyDir) {
66
- throw new KnownException('Can not find terraform files. Command needs to be run in a directory with terraform files');
67
- }
68
- }
69
25
  tfArgs(env, cwd) {
70
26
  const varDefs = this.getVarDefs(cwd);
71
27
  const argVars = this.getArgVars(env.args);
@@ -3,6 +3,5 @@ export { createEphemeral } from './createEphemeral.js';
3
3
  export { deleteIt } from './delete.js';
4
4
  export { deploy } from './deploy.js';
5
5
  export { destroy } from './destroy.js';
6
- export { init } from './init.js';
7
6
  export { plan } from './plan.js';
8
7
  export { status } from './status.js';
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import { createRequire } from 'module';
3
3
  import { Command } from 'commander';
4
4
  import updateNotifier from 'update-notifier';
5
- import { configure, createEphemeral, deleteIt, deploy, destroy, init, plan, status } from './commands/index.js';
5
+ import { configure, createEphemeral, deleteIt, deploy, destroy, plan, status } from './commands/index.js';
6
6
  const require = createRequire(import.meta.url);
7
7
  const pkg = require('../package.json');
8
8
  updateNotifier({ pkg, updateCheckInterval: 0 }).notify();
@@ -16,7 +16,6 @@ createEphemeral(program);
16
16
  deleteIt(program);
17
17
  deploy(program);
18
18
  destroy(program);
19
- init(program);
20
19
  plan(program);
21
20
  status(program);
22
21
  program.parse(process.argv);
@@ -58,9 +58,6 @@ export class EnvCtl {
58
58
  }
59
59
  throw new KnownException(`Env ${env.key} status is ${env.status}, can not run this command`);
60
60
  }
61
- async init(key, cwd) {
62
- await this.terraformAdapter.init(key, cwd, true);
63
- }
64
61
  async plan(input, tfArgs, cwd) {
65
62
  const { anOwner, key, env } = await this.tryGetEnv(input);
66
63
  if (env == null) {
@@ -79,7 +76,6 @@ export class EnvCtl {
79
76
  }
80
77
  async runPlan(key, owner, args, vars, cwd) {
81
78
  const envTerraform = { key, ephemeral: false, owner, args, vars };
82
- await this.terraformAdapter.init(key, cwd);
83
79
  await this.terraformAdapter.plan(envTerraform, cwd);
84
80
  }
85
81
  async createEphemeral(key, owner) {
@@ -120,7 +116,6 @@ export class EnvCtl {
120
116
  await this.runDeploy(env, key, tfArgs, cwd);
121
117
  }
122
118
  async runDeploy(env, key, tfArgs, cwd) {
123
- await this.terraformAdapter.init(env.key, cwd);
124
119
  console.log('Deploying resources');
125
120
  const { ephemeral, vars } = env;
126
121
  const envTerraform = { key, ephemeral, owner: env.owner || 'system', args: tfArgs, vars };
@@ -191,7 +186,6 @@ export class EnvCtl {
191
186
  const { ephemeral, owner, vars } = env;
192
187
  const envTerraform = { key, ephemeral, owner: owner || 'system', args: tfArgs, vars };
193
188
  console.log('Destroying env resources');
194
- await this.terraformAdapter.init(env.key, cwd);
195
189
  await this.terraformAdapter.destroy(envTerraform, force, cwd);
196
190
  console.log('Unlock env');
197
191
  await this.envApi.activate(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.25.0",
4
+ "version": "0.26.0",
5
5
  "author": "Alex Chekulaev",
6
6
  "type": "module",
7
7
  "bin": {
@@ -30,16 +30,15 @@
30
30
  "run-configure": "tsc --sourceMap true && npm run run -- configure",
31
31
  "~": "",
32
32
  "run-init": "cd ../tt-core && terraform init -backend-config=key=laxa1986 -upgrade",
33
- "*": "",
34
33
  "run-status": " tsc --sourceMap true && npm run run -- status --cwd ../tt-core",
35
34
  "run-plan": " tsc --sourceMap true && npm run run -- plan --cwd ../tt-core",
36
35
  "run-deploy": " tsc --sourceMap true && npm run run -- deploy --cwd ../tt-core -var=\"env_size=min\"",
37
36
  "run-delete": " tsc --sourceMap true && npm run run -- delete --cwd ../tt-core",
38
37
  "run-destroy": "tsc --sourceMap true && npm run run -- destroy --cwd ../tt-core",
39
38
  "-": "",
39
+ "run-ephemeral-init": "cd ../tt-gitops && terraform init -backend-config=key=test",
40
40
  "run-ephemeral-create": " tsc --sourceMap true && npm run run -- create-ephemeral --env test",
41
41
  "run-ephemeral-status": " tsc --sourceMap true && npm run run -- status --env test",
42
- "run-ephemeral-init": " tsc --sourceMap true && npm run run -- init --env test --cwd ../tt-gitops",
43
42
  "run-ephemeral-deploy": " tsc --sourceMap true && npm run run -- deploy --env test --cwd ../tt-gitops -var-file=versions.tfvars",
44
43
  "run-ephemeral-delete": " tsc --sourceMap true && npm run run -- delete --env test --cwd ../tt-gitops --force",
45
44
  "run-ephemeral-destroy": "tsc --sourceMap true && npm run run -- destroy --env test --cwd ../tt-gitops --force -var-file=versions.tfvars"
@@ -1,17 +0,0 @@
1
- import { Command } from 'commander';
2
- import { cliHelper, envCtl } from '../container.js';
3
- import { _keys } from './_keys.js';
4
- import { wrap } from './_utils.js';
5
- export function init(program) {
6
- program
7
- .command('init')
8
- .description('Terraform init wrapper')
9
- .option('--key <key>', _keys.KEY)
10
- .option('--cwd <cwd>', _keys.CWD)
11
- .action(wrap(handler));
12
- }
13
- async function handler(options) {
14
- const { key, cwd } = options;
15
- const theKey = cliHelper.ensureEnv(key);
16
- await envCtl.init(theKey, cwd);
17
- }