@agilecustoms/envctl 0.27.0 → 0.27.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.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -10,9 +10,14 @@ const RETRYABLE_ERRORS = [
|
|
|
10
10
|
export class TerraformAdapter {
|
|
11
11
|
processRunner;
|
|
12
12
|
cliHelper;
|
|
13
|
-
|
|
13
|
+
backends;
|
|
14
|
+
constructor(processRunner, cliHelper, backends) {
|
|
14
15
|
this.processRunner = processRunner;
|
|
15
16
|
this.cliHelper = cliHelper;
|
|
17
|
+
this.backends = backends.reduce((acc, backend) => {
|
|
18
|
+
acc.set(backend.getType(), backend);
|
|
19
|
+
return acc;
|
|
20
|
+
}, new Map());
|
|
16
21
|
}
|
|
17
22
|
getKey(cwd) {
|
|
18
23
|
const dir = cwd ?? process.cwd();
|
|
@@ -34,13 +39,15 @@ export class TerraformAdapter {
|
|
|
34
39
|
catch (err) {
|
|
35
40
|
throw new KnownException(`Failed to parse terraform state file: ${statePath}`, { cause: err });
|
|
36
41
|
}
|
|
37
|
-
const
|
|
38
|
-
const type =
|
|
39
|
-
|
|
40
|
-
|
|
42
|
+
const backendJson = tfstate.backend;
|
|
43
|
+
const type = backendJson?.type;
|
|
44
|
+
const backend = this.backends.get(type);
|
|
45
|
+
if (backend === undefined) {
|
|
46
|
+
const supportedBackends = Array.from(this.backends.keys()).join(',');
|
|
47
|
+
throw new KnownException(`Unsupported terraform backend type: ${type}. Supported types: ${supportedBackends}`);
|
|
41
48
|
}
|
|
42
|
-
const config =
|
|
43
|
-
const key = config
|
|
49
|
+
const config = backendJson?.config;
|
|
50
|
+
const key = backend.getKey(config);
|
|
44
51
|
if (!key) {
|
|
45
52
|
throw new KnownException(`Terraform backend config does not contain 'key' attribute`);
|
|
46
53
|
}
|
|
@@ -6,12 +6,11 @@ export function createEphemeral(program) {
|
|
|
6
6
|
program
|
|
7
7
|
.command('create-ephemeral')
|
|
8
8
|
.description('Create bare env w/o resources. Used in CI as first step just to pre-generate token for extension')
|
|
9
|
-
.
|
|
10
|
-
.option('--owner <owner>', _keys.OWNER)
|
|
9
|
+
.option('--cwd <cwd>', _keys.CWD)
|
|
11
10
|
.action(wrap(handler));
|
|
12
11
|
}
|
|
13
12
|
async function handler(options) {
|
|
14
|
-
const {
|
|
15
|
-
const token = await envCtl.createEphemeral(
|
|
13
|
+
const { cwd } = options;
|
|
14
|
+
const token = await envCtl.createEphemeral(cwd);
|
|
16
15
|
console.log(token);
|
|
17
16
|
}
|
package/dist/container.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
|
+
import { S3Backend } from './backend/S3Backend.js';
|
|
1
2
|
import { AwsCredsHelper } from './client/AwsCredsHelper.js';
|
|
2
3
|
import { CliHelper, EnvApiClient, HttpClient, TerraformAdapter } from './client/index.js';
|
|
3
4
|
import { ProcessRunner } from './client/ProcessRunner.js';
|
|
4
5
|
import { ConfigService, EnvCtl } from './service/index.js';
|
|
5
6
|
const cliHelper = new CliHelper();
|
|
7
|
+
const configService = new ConfigService();
|
|
6
8
|
const awsCredsHelper = new AwsCredsHelper();
|
|
9
|
+
const backends = [
|
|
10
|
+
new S3Backend()
|
|
11
|
+
];
|
|
7
12
|
const httpClient = new HttpClient(awsCredsHelper);
|
|
8
13
|
const envApiClient = new EnvApiClient(httpClient);
|
|
9
14
|
const processRunner = new ProcessRunner();
|
|
10
|
-
const terraformAdapter = new TerraformAdapter(processRunner, cliHelper);
|
|
11
|
-
const configService = new ConfigService();
|
|
15
|
+
const terraformAdapter = new TerraformAdapter(processRunner, cliHelper, backends);
|
|
12
16
|
const envCtl = new EnvCtl(cliHelper, envApiClient, terraformAdapter, configService);
|
|
13
|
-
export { awsCredsHelper,
|
|
17
|
+
export { awsCredsHelper, configService, envCtl };
|
package/dist/service/EnvCtl.js
CHANGED
|
@@ -46,6 +46,8 @@ export class EnvCtl {
|
|
|
46
46
|
return env;
|
|
47
47
|
}
|
|
48
48
|
checkInput(env, owner, cwd) {
|
|
49
|
+
if (env.ephemeral)
|
|
50
|
+
return;
|
|
49
51
|
if (env.owner !== owner) {
|
|
50
52
|
throw new KnownException(`Can not change env owner ${env.owner} -> ${owner}`);
|
|
51
53
|
}
|
|
@@ -86,12 +88,13 @@ export class EnvCtl {
|
|
|
86
88
|
const envTerraform = { key, ephemeral: false, owner, args, vars };
|
|
87
89
|
await this.terraformAdapter.plan(envTerraform, cwd);
|
|
88
90
|
}
|
|
89
|
-
async createEphemeral(
|
|
91
|
+
async createEphemeral(cwd) {
|
|
92
|
+
const key = this.terraformAdapter.getKey(cwd);
|
|
90
93
|
const env = await this.envApi.get(key);
|
|
91
94
|
if (env !== null) {
|
|
92
95
|
throw new KnownException(`Env ${key} already exists`);
|
|
93
96
|
}
|
|
94
|
-
const createEnv = { key
|
|
97
|
+
const createEnv = { key };
|
|
95
98
|
return await this.envApi.createEphemeral(createEnv);
|
|
96
99
|
}
|
|
97
100
|
async deploy(tfArgs, cwd) {
|
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.27.
|
|
4
|
+
"version": "0.27.1",
|
|
5
5
|
"author": "Alex Chekulaev",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"bin": {
|
|
@@ -29,15 +29,15 @@
|
|
|
29
29
|
"run-version": " tsc --sourceMap true && npm run run -- --version",
|
|
30
30
|
"run-configure": "tsc --sourceMap true && npm run run -- configure",
|
|
31
31
|
"~": "",
|
|
32
|
-
"run-init": "cd ../tt-core && terraform init -backend-config=key=laxa1986
|
|
32
|
+
"run-init": "cd ../tt-core && terraform init -upgrade -backend-config=key=laxa1986",
|
|
33
33
|
"run-status": " tsc --sourceMap true && npm run run -- status --cwd ../tt-core",
|
|
34
34
|
"run-plan": " tsc --sourceMap true && npm run run -- plan --cwd ../tt-core",
|
|
35
35
|
"run-deploy": " tsc --sourceMap true && npm run run -- deploy --cwd ../tt-core -var=\"env_size=min\"",
|
|
36
36
|
"run-delete": " tsc --sourceMap true && npm run run -- delete --cwd ../tt-core",
|
|
37
37
|
"run-destroy": "tsc --sourceMap true && npm run run -- destroy --cwd ../tt-core",
|
|
38
38
|
"-": "",
|
|
39
|
-
"run-ephemeral-init": "cd ../tt-gitops && terraform init -backend-config=key=test",
|
|
40
|
-
"run-ephemeral-create": " tsc --sourceMap true && npm run run -- create-ephemeral",
|
|
39
|
+
"run-ephemeral-init": "cd ../tt-gitops && terraform init -upgrade -backend-config=key=test -reconfigure",
|
|
40
|
+
"run-ephemeral-create": " tsc --sourceMap true && npm run run -- create-ephemeral --cwd ../tt-gitops",
|
|
41
41
|
"run-ephemeral-status": " tsc --sourceMap true && npm run run -- status --key test",
|
|
42
42
|
"run-ephemeral-deploy": " tsc --sourceMap true && npm run run -- deploy --cwd ../tt-gitops -var-file=versions.tfvars",
|
|
43
43
|
"run-ephemeral-delete": " tsc --sourceMap true && npm run run -- delete --cwd ../tt-gitops --force",
|