@agilecustoms/envctl 1.24.0 → 1.25.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.
@@ -51,6 +51,7 @@ export class EnvService extends BaseService {
51
51
  async plan(tfArgs) {
52
52
  this.terraformAdapter.validateAndGetStateFile();
53
53
  const key = this.terraformAdapter.getKey();
54
+ this.terraformAdapter.getLockFile();
54
55
  await this.terraformAdapter.plan(key, tfArgs);
55
56
  }
56
57
  async createEphemeral(key) {
@@ -108,22 +108,27 @@ export class TerraformAdapter {
108
108
  config.stateHash = fileHash;
109
109
  return { stateFile: fileContent, stateUpdated };
110
110
  }
111
- getLockFile() {
111
+ _getLockFile() {
112
112
  const lockPath = path.join(process.cwd(), '.terraform.lock.hcl');
113
113
  if (!fs.existsSync(lockPath)) {
114
114
  throw new KnownException(`Terraform lock file not found at: ${lockPath}`);
115
115
  }
116
- let fileContent;
117
116
  try {
118
- fileContent = fs.readFileSync(lockPath, 'utf8');
117
+ return fs.readFileSync(lockPath, 'utf8');
119
118
  }
120
119
  catch (cause) {
121
120
  throw new KnownException(`Failed to read terraform lock file: ${lockPath}`, { cause });
122
121
  }
122
+ }
123
+ getLockFile() {
124
+ const fileContent = this._getLockFile();
123
125
  const config = this.localStateService.load();
124
126
  const fileHash = hash(fileContent);
127
+ if (fileHash !== config.lockFileHash) {
128
+ throw new KnownException(`Make sure you're using envctl init instead of terraform init`);
129
+ }
125
130
  const lockUpdated = config.lockHash !== fileHash;
126
- config.stateHash = fileHash;
131
+ config.lockHash = fileHash;
127
132
  return { lockFile: fileContent, lockUpdated };
128
133
  }
129
134
  saveHashes() {
@@ -136,6 +141,10 @@ export class TerraformAdapter {
136
141
  logger.info('Lock providers');
137
142
  await this.cli.run('terraform', ['providers', 'lock', '-platform=linux_arm64']);
138
143
  }
144
+ const fileContent = this._getLockFile();
145
+ const config = this.localStateService.load();
146
+ config.lockFileHash = hash(fileContent);
147
+ this.localStateService.save(config);
139
148
  }
140
149
  printTime() {
141
150
  const now = new Date();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agilecustoms/envctl",
3
- "version": "1.24.0",
3
+ "version": "1.25.0",
4
4
  "description": "node.js CLI client for manage environments",
5
5
  "keywords": [
6
6
  "terraform wrapper",
@@ -64,12 +64,13 @@
64
64
  "d3-apply": " npm run d3 -- apply plan",
65
65
  "d3-delete": "npm run d3 -- delete",
66
66
  "-d4-": "",
67
- "d4-desc": "terraform plan and then envctl apply",
67
+ "d4-desc": "terraform init and then envctl apply",
68
68
  "d4": "CWD=../tt-core npm run it --",
69
- "d4-init": "cd ../tt-core && rm .terraform.lock.hcl && terraform init -reconfigure -upgrade -backend-config=key=d4",
70
- "d4-plan": "cd ../tt-core && terraform plan -var=env_size=min -var=env=d4 -out=plan",
71
- "d4-apply": " npm run d4 -- apply plan",
69
+ "d4-init": "cd ../tt-core && rm .terraform.lock.hcl && rm .terraform/envctl.json && terraform init -reconfigure -upgrade -backend-config=key=d4",
70
+ "d4-init1": " npm run d4 -- init -reconfigure -upgrade -backend-config=key=d4",
71
+ "d4-apply": " npm run d4 -- apply -auto-approve -var=env_size=min",
72
72
  "d4-delete": "npm run d4 -- delete",
73
+ "d4-status": "npm run d4 -- status",
73
74
  "-e1-": "",
74
75
  "e1-desc": "ephemeral env in CI (must have ENVCTL_API_KEY_ in env vars)",
75
76
  "e1": "CWD=../tt-core CI=true ENVCTL_HOME=non-existing ENVCTL_API_KEY=\"$ENVCTL_API_KEY_\" npm run it --",