@agilecustoms/envctl 1.18.2 → 1.19.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.
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { confirm } from '@inquirer/prompts';
|
|
2
1
|
import { Cli } from '../client/Cli.js';
|
|
3
2
|
import { EnvApiClient } from '../client/index.js';
|
|
4
3
|
import { KnownException } from '../exceptions.js';
|
|
@@ -6,7 +5,6 @@ import { logger } from '../logger.js';
|
|
|
6
5
|
import { EnvStatus } from '../model/index.js';
|
|
7
6
|
import { toLocalTime } from '../util.js';
|
|
8
7
|
import { BaseService } from './BaseService.js';
|
|
9
|
-
export const PLAN_FILE = '.terraform/envctl.plan';
|
|
10
8
|
export class EnvService extends BaseService {
|
|
11
9
|
cli;
|
|
12
10
|
envApi;
|
|
@@ -82,26 +80,6 @@ export class EnvService extends BaseService {
|
|
|
82
80
|
}
|
|
83
81
|
}
|
|
84
82
|
}
|
|
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
83
|
handleDeleteStatuses(env) {
|
|
106
84
|
if (env.status === EnvStatus.Deleting) {
|
|
107
85
|
throw new KnownException(`Env ${env.key} status is DELETING, please wait.\n
|
|
@@ -119,7 +97,6 @@ export class EnvService extends BaseService {
|
|
|
119
97
|
const dir = this.cli.getDir();
|
|
120
98
|
const createEnv = { key, dir };
|
|
121
99
|
await this.lockTerraform(createEnv, true);
|
|
122
|
-
tfArgs = await this.ensurePlan({ key, ephemeral: false }, tfArgs);
|
|
123
100
|
logger.info('Creating env metadata');
|
|
124
101
|
env = await this.envApi.create(createEnv);
|
|
125
102
|
await this.runApply(env, tfArgs);
|
|
@@ -128,19 +105,9 @@ export class EnvService extends BaseService {
|
|
|
128
105
|
this.checkDir(env);
|
|
129
106
|
this.handleDeleteStatuses(env);
|
|
130
107
|
const status = env.status;
|
|
131
|
-
if (status === EnvStatus.Deploying || status === EnvStatus.Updating) {
|
|
132
|
-
const message = `Env status is ${status}, likely due to an error from a previous run\n
|
|
133
|
-
Do you want to proceed with deployment?`;
|
|
134
|
-
const answerYes = await confirm({ message });
|
|
135
|
-
if (!answerYes) {
|
|
136
|
-
logger.info('Aborting deployment');
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
108
|
if (status === EnvStatus.Init || status === EnvStatus.Active) {
|
|
141
109
|
logger.info(`Env status is ${status}`);
|
|
142
110
|
await this.lockTerraform(env);
|
|
143
|
-
tfArgs = await this.ensurePlan(env, tfArgs);
|
|
144
111
|
if (env.status == EnvStatus.Active) {
|
|
145
112
|
logger.info('Will lock for update and run terraform apply (to update resources)');
|
|
146
113
|
}
|
|
@@ -148,12 +115,11 @@ export class EnvService extends BaseService {
|
|
|
148
115
|
await this.runApply(env, tfArgs);
|
|
149
116
|
return;
|
|
150
117
|
}
|
|
151
|
-
tfArgs = await this.ensurePlan(env, tfArgs);
|
|
152
118
|
await this.runApply(env, tfArgs);
|
|
153
119
|
}
|
|
154
120
|
async runApply(env, tfArgs) {
|
|
155
121
|
logger.info('Deploying resources');
|
|
156
|
-
await this.terraformAdapter.apply(
|
|
122
|
+
await this.terraformAdapter.apply(env, tfArgs);
|
|
157
123
|
logger.info('Activating env (to finish creation)');
|
|
158
124
|
await this.envApi.activate(env);
|
|
159
125
|
}
|
|
@@ -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.1",
|
|
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",
|