@agilecustoms/envctl 0.37.1 → 0.37.3

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.
@@ -135,7 +135,7 @@ export class TerraformAdapter {
135
135
  const keyValue = arg.slice(5);
136
136
  const eqIndex = keyValue.indexOf('=');
137
137
  if (eqIndex === -1) {
138
- console.log('terraform var argument is not in key=value format:', arg);
138
+ console.error('Terraform var argument is not in key=value format:', arg);
139
139
  return;
140
140
  }
141
141
  const key = keyValue.slice(0, eqIndex);
@@ -84,23 +84,28 @@ export class EnvService {
84
84
  const createEnv = { key };
85
85
  return await this.envApi.createEphemeral(createEnv);
86
86
  }
87
- async lockTerraform(env, cwd) {
87
+ async lockTerraform(env, cwd, newEnv = false) {
88
88
  const config = this.localStateService.load(cwd);
89
- console.log('validate terraform.tfstate file');
89
+ console.log('Validate terraform.tfstate file');
90
90
  const stateFileContent = this.terraformAdapter.getTerraformBackend(cwd).validateAndGetStateFileContent();
91
91
  const stateHash = this.localStateService.hash(stateFileContent);
92
- if (config.stateHash !== stateHash) {
92
+ if (config.stateHash !== stateHash || newEnv) {
93
93
  config.stateHash = stateHash;
94
94
  env.stateFile = stateFileContent;
95
95
  }
96
96
  const linuxArm64 = process.platform === 'linux' && process.arch === 'arm64';
97
- if (!linuxArm64) {
97
+ if (!linuxArm64 || newEnv) {
98
98
  let lockFileContent = this.terraformAdapter.getLockFile(cwd);
99
- const lockFileHash = this.localStateService.hash(lockFileContent);
100
- if (config.lockHash !== lockFileHash) {
101
- await this.terraformAdapter.lockProviders(cwd);
102
- lockFileContent = this.terraformAdapter.getLockFile(cwd);
103
- config.lockHash = this.localStateService.hash(lockFileContent);
99
+ if (!linuxArm64) {
100
+ const lockFileHash = this.localStateService.hash(lockFileContent);
101
+ if (config.lockHash !== lockFileHash) {
102
+ await this.terraformAdapter.lockProviders(cwd);
103
+ lockFileContent = this.terraformAdapter.getLockFile(cwd);
104
+ config.lockHash = this.localStateService.hash(lockFileContent);
105
+ env.lockFile = lockFileContent;
106
+ }
107
+ }
108
+ if (newEnv) {
104
109
  env.lockFile = lockFileContent;
105
110
  }
106
111
  }
@@ -114,7 +119,7 @@ export class EnvService {
114
119
  const kind = this.cliHelper.getKind(cwd);
115
120
  console.log(`Inferred kind from directory name: ${kind}`);
116
121
  const createEnv = { key, kind };
117
- await this.lockTerraform(createEnv, cwd);
122
+ await this.lockTerraform(createEnv, cwd, true);
118
123
  console.log('Creating env metadata');
119
124
  env = await this.envApi.create(createEnv);
120
125
  await this.runDeploy(env, key, tfArgs, cwd);
@@ -124,7 +129,7 @@ export class EnvService {
124
129
  switch (env.status) {
125
130
  case EnvStatus.Init:
126
131
  this.localStateService.init(cwd);
127
- await this.lockTerraform(env, cwd);
132
+ await this.lockTerraform(env, cwd, true);
128
133
  await this.envApi.lockForUpdate(env);
129
134
  break;
130
135
  case EnvStatus.Active:
@@ -31,16 +31,16 @@ export class LocalStateService {
31
31
  this.config = config;
32
32
  return;
33
33
  }
34
- console.log('local state file version mismatch, re-initializing');
34
+ console.log('Local state file version mismatch, re-initializing');
35
35
  this.createEmptyConfig(filePath);
36
36
  }
37
37
  load(cwd) {
38
38
  if (this.config)
39
39
  return this.config;
40
- console.log('load local state config');
40
+ console.log('Load local state config');
41
41
  const filePath = this.filePath(cwd);
42
42
  if (!fs.existsSync(filePath)) {
43
- console.warn('local state file does not exist, must have been accidentally deleted, re-initializing');
43
+ console.warn('Local state file does not exist, must have been accidentally deleted, re-initializing');
44
44
  return this.createEmptyConfig(filePath);
45
45
  }
46
46
  const data = fs.readFileSync(filePath, 'utf-8');
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.37.1",
4
+ "version": "0.37.3",
5
5
  "author": "Alex Chekulaev",
6
6
  "type": "module",
7
7
  "engines": {