@agilecustoms/envctl 1.18.2 → 1.19.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.
|
@@ -6,7 +6,6 @@ import { logger } from '../logger.js';
|
|
|
6
6
|
import { EnvStatus } from '../model/index.js';
|
|
7
7
|
import { toLocalTime } from '../util.js';
|
|
8
8
|
import { BaseService } from './BaseService.js';
|
|
9
|
-
export const PLAN_FILE = '.terraform/envctl.plan';
|
|
10
9
|
export class EnvService extends BaseService {
|
|
11
10
|
cli;
|
|
12
11
|
envApi;
|
|
@@ -82,26 +81,6 @@ export class EnvService extends BaseService {
|
|
|
82
81
|
}
|
|
83
82
|
}
|
|
84
83
|
}
|
|
85
|
-
async ensurePlan(env, args) {
|
|
86
|
-
if (args.length > 0 && !args[0].startsWith('-')) {
|
|
87
|
-
return args;
|
|
88
|
-
}
|
|
89
|
-
await this.terraformAdapter.plan(env, [`-out=${PLAN_FILE}`, ...args]);
|
|
90
|
-
const PLAN_ARGS = ['-var', '-target', '-replace', '-refresh'];
|
|
91
|
-
const applyArgs = [PLAN_FILE];
|
|
92
|
-
for (let i = 0; i < args.length; i++) {
|
|
93
|
-
const arg = args[i];
|
|
94
|
-
if (arg === '-var' || arg === '-var-file') {
|
|
95
|
-
i++;
|
|
96
|
-
continue;
|
|
97
|
-
}
|
|
98
|
-
if (PLAN_ARGS.some(planArg => arg.startsWith(planArg))) {
|
|
99
|
-
continue;
|
|
100
|
-
}
|
|
101
|
-
applyArgs.push(arg);
|
|
102
|
-
}
|
|
103
|
-
return applyArgs;
|
|
104
|
-
}
|
|
105
84
|
handleDeleteStatuses(env) {
|
|
106
85
|
if (env.status === EnvStatus.Deleting) {
|
|
107
86
|
throw new KnownException(`Env ${env.key} status is DELETING, please wait.\n
|
|
@@ -119,7 +98,6 @@ export class EnvService extends BaseService {
|
|
|
119
98
|
const dir = this.cli.getDir();
|
|
120
99
|
const createEnv = { key, dir };
|
|
121
100
|
await this.lockTerraform(createEnv, true);
|
|
122
|
-
tfArgs = await this.ensurePlan({ key, ephemeral: false }, tfArgs);
|
|
123
101
|
logger.info('Creating env metadata');
|
|
124
102
|
env = await this.envApi.create(createEnv);
|
|
125
103
|
await this.runApply(env, tfArgs);
|
|
@@ -140,7 +118,6 @@ export class EnvService extends BaseService {
|
|
|
140
118
|
if (status === EnvStatus.Init || status === EnvStatus.Active) {
|
|
141
119
|
logger.info(`Env status is ${status}`);
|
|
142
120
|
await this.lockTerraform(env);
|
|
143
|
-
tfArgs = await this.ensurePlan(env, tfArgs);
|
|
144
121
|
if (env.status == EnvStatus.Active) {
|
|
145
122
|
logger.info('Will lock for update and run terraform apply (to update resources)');
|
|
146
123
|
}
|
|
@@ -148,12 +125,11 @@ export class EnvService extends BaseService {
|
|
|
148
125
|
await this.runApply(env, tfArgs);
|
|
149
126
|
return;
|
|
150
127
|
}
|
|
151
|
-
tfArgs = await this.ensurePlan(env, tfArgs);
|
|
152
128
|
await this.runApply(env, tfArgs);
|
|
153
129
|
}
|
|
154
130
|
async runApply(env, tfArgs) {
|
|
155
131
|
logger.info('Deploying resources');
|
|
156
|
-
await this.terraformAdapter.apply(
|
|
132
|
+
await this.terraformAdapter.apply(env, tfArgs);
|
|
157
133
|
logger.info('Activating env (to finish creation)');
|
|
158
134
|
await this.envApi.activate(env);
|
|
159
135
|
}
|
|
@@ -120,7 +120,7 @@ export class TerraformAdapter {
|
|
|
120
120
|
});
|
|
121
121
|
logger.info(`\nTime EDT: ${edt}, UTC: ${utc}\n`);
|
|
122
122
|
}
|
|
123
|
-
tfArgs(env, args
|
|
123
|
+
tfArgs(env, args) {
|
|
124
124
|
const varDefs = this.getVarDefs();
|
|
125
125
|
const argVars = this.getArgVars(args);
|
|
126
126
|
const extraArgs = [];
|
|
@@ -141,11 +141,6 @@ export class TerraformAdapter {
|
|
|
141
141
|
extraArgs.push('-var=' + name + '=' + specialFields[name]);
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
|
-
Object.entries(vars || {}).forEach(([key, value]) => {
|
|
145
|
-
if (varDefs[key] && !argVars[key]) {
|
|
146
|
-
extraArgs.push('-var=' + key + '=' + value);
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
144
|
return [...extraArgs, ...args];
|
|
150
145
|
}
|
|
151
146
|
getVarDefs() {
|
|
@@ -214,10 +209,11 @@ export class TerraformAdapter {
|
|
|
214
209
|
throw new KnownException(`terraform plan failed with code ${error.code}:\n${error.message}`, { cause: error });
|
|
215
210
|
}
|
|
216
211
|
}
|
|
217
|
-
async apply(
|
|
212
|
+
async apply(env, args) {
|
|
213
|
+
args = this.tfArgs(env, args);
|
|
218
214
|
logger.info('Running: terraform apply ' + args.join(' ') + '\n');
|
|
219
215
|
try {
|
|
220
|
-
await this._apply(args, ttl, 1);
|
|
216
|
+
await this._apply(args, env.ttl, 1);
|
|
221
217
|
}
|
|
222
218
|
catch (error) {
|
|
223
219
|
if (error instanceof TimeoutException) {
|
|
@@ -237,8 +233,9 @@ export class TerraformAdapter {
|
|
|
237
233
|
throw new KnownException('TTL expired before terraform apply could start');
|
|
238
234
|
}
|
|
239
235
|
logger.debug('timeout(ms): ' + timeoutMs);
|
|
236
|
+
logger.info('Running: terraform apply ' + args.join(' ') + '\n');
|
|
240
237
|
try {
|
|
241
|
-
await this.cli.run('terraform', ['apply', ...args], { timeoutMs });
|
|
238
|
+
await this.cli.run('terraform', ['apply', ...args], { timeoutMs, interactive: true });
|
|
242
239
|
this.printTime();
|
|
243
240
|
}
|
|
244
241
|
catch (error) {
|
|
@@ -269,9 +266,9 @@ export class TerraformAdapter {
|
|
|
269
266
|
wrongDir = true;
|
|
270
267
|
}
|
|
271
268
|
};
|
|
272
|
-
logger.info('Running: terraform destroy
|
|
269
|
+
logger.info('Running: terraform destroy ' + args.join(' ') + '\n');
|
|
273
270
|
try {
|
|
274
|
-
await this.cli.run('terraform', ['destroy',
|
|
271
|
+
await this.cli.run('terraform', ['destroy', ...args], { outScanner, interactive: true });
|
|
275
272
|
}
|
|
276
273
|
catch (error) {
|
|
277
274
|
if (!(error instanceof ProcessException)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agilecustoms/envctl",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.19.0",
|
|
4
4
|
"description": "node.js CLI client for manage environments",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"terraform wrapper",
|
|
@@ -46,13 +46,14 @@
|
|
|
46
46
|
"run-core-plan": " CWD=../tt-core npm run it -- plan -out=.terraform/plan",
|
|
47
47
|
"run-core-applyp": " CWD=../tt-core npm run it -- apply .terraform/plan",
|
|
48
48
|
"run-core-apply": " CWD=../tt-core npm run it -- apply",
|
|
49
|
+
"run-core-applya": " CWD=../tt-core npm run it -- apply --auto-approve",
|
|
49
50
|
"run-core-delete": " CWD=../tt-core npm run it -- delete",
|
|
50
51
|
"run-core-destroy": "CWD=../tt-core npm run it -- destroy",
|
|
51
52
|
"run-core-logs": " CWD=../tt-core npm run it -- logs",
|
|
52
53
|
"*": "",
|
|
53
54
|
"run-init": "cd ../tt-gitops && terraform init -upgrade -backend-config=key=laxa1986 -reconfigure",
|
|
54
55
|
"run-status": " CWD=../tt-gitops npm run it -- status",
|
|
55
|
-
"run-plan": "
|
|
56
|
+
"run-plan": " AWS_PROFILE=ac-tt-dev-deployer CWD=../tt-gitops npm run it -- plan -var-file=versions.tfvars",
|
|
56
57
|
"run-apply": " AWS_PROFILE=ac-tt-dev-deployer CWD=../tt-gitops npm run it -- apply -var-file=versions.tfvars",
|
|
57
58
|
"run-delete": " CWD=../tt-gitops npm run it -- delete",
|
|
58
59
|
"run-destroy": "AWS_PROFILE=ac-tt-dev-destroyer CWD=../tt-gitops npm run it -- destroy -var-file=versions.tfvars",
|