@agilecustoms/envctl 0.31.0 → 0.32.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.
@@ -12,6 +12,15 @@ export class S3Backend extends TerraformBackend {
12
12
  return key;
13
13
  }
14
14
  validateAndGetStateFileContent() {
15
+ const allowedKeys = ['bucket', 'dynamodb_table', 'key', 'region', 'use_lockfile'];
16
+ const nonEmptyKeys = Object.keys(this.config).filter(key => this.config[key] !== null);
17
+ const invalidKeys = nonEmptyKeys.filter(key => !allowedKeys.includes(key));
18
+ if (invalidKeys.length > 0) {
19
+ throw new KnownException(`Terraform local state file ${this.stateFilePath}\n`
20
+ + `backend config contains not allowed keys: ${invalidKeys.join(', ')}\n`
21
+ + `Allowed keys are: ${allowedKeys.join(', ')}\n`
22
+ + `Contact support if you think your backend config is valid`);
23
+ }
15
24
  return this.stateFileContent;
16
25
  }
17
26
  }
@@ -1,7 +1,9 @@
1
1
  export class TerraformBackend {
2
+ stateFilePath = '';
2
3
  stateFileContent = '';
3
4
  config = {};
4
- setState(stateFileContent, config) {
5
+ setState(stateFilePath, stateFileContent, config) {
6
+ this.stateFilePath = stateFilePath;
5
7
  this.stateFileContent = stateFileContent;
6
8
  this.config = config;
7
9
  }
@@ -12,9 +12,7 @@ export class CliHelper {
12
12
  return answer;
13
13
  }
14
14
  getKind(cwd) {
15
- const kind = getDirName(cwd);
16
- console.log(`Inferred kind from directory name: ${kind}`);
17
- return kind;
15
+ return getDirName(cwd);
18
16
  }
19
17
  }
20
18
  function getDirName(cwd) {
@@ -63,7 +63,7 @@ export class TerraformAdapter {
63
63
  const supportedBackends = Array.from(this.backends.keys()).join(',');
64
64
  throw new KnownException(`Unsupported terraform backend type: ${type}. Supported types: ${supportedBackends}`);
65
65
  }
66
- backend.setState(stateFileContent, backendJson.config);
66
+ backend.setState(statePath, stateFileContent, backendJson.config);
67
67
  this.backend = backend;
68
68
  return backend;
69
69
  }
@@ -105,8 +105,9 @@ export class EnvCtl {
105
105
  return await this.envApi.createEphemeral(createEnv);
106
106
  }
107
107
  async lockTerraform(env, cwd) {
108
- await this.terraformAdapter.lockProviders(cwd);
108
+ console.log('validate terraform.tfstate file');
109
109
  env.stateFile = this.terraformAdapter.getTerraformBackend(cwd).validateAndGetStateFileContent();
110
+ await this.terraformAdapter.lockProviders(cwd);
110
111
  env.lockFile = this.terraformAdapter.getLockFile(cwd);
111
112
  }
112
113
  async deploy(tfArgs, cwd) {
@@ -114,10 +115,11 @@ export class EnvCtl {
114
115
  let env = await this.tryGetEnv(key);
115
116
  if (env === null) {
116
117
  const kind = this.cliHelper.getKind(cwd);
117
- console.log('Creating env metadata');
118
+ console.log(`Inferred kind from directory name: ${kind}`);
118
119
  const userName = this.configService.getUserName();
119
120
  const createEnv = { key, owner: userName, kind };
120
121
  await this.lockTerraform(createEnv, cwd);
122
+ console.log('Creating env metadata');
121
123
  env = await this.envApi.create(createEnv);
122
124
  }
123
125
  else {
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.31.0",
4
+ "version": "0.32.1",
5
5
  "author": "Alex Chekulaev",
6
6
  "type": "module",
7
7
  "bin": {