@hiiretail/gcp-infra-generators 1.0.0 → 1.0.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.
Files changed (55) hide show
  1. package/dist/generators/clan-resources/clan-project/index.js +89 -189
  2. package/dist/generators/common-resources/bigquery/index.js +172 -267
  3. package/dist/generators/common-resources/budget/index.js +67 -153
  4. package/dist/generators/common-resources/cloud-armor/index.js +17 -167
  5. package/dist/generators/common-resources/cloud-storage/index.js +96 -205
  6. package/dist/generators/common-resources/cloudsql/index.js +71 -177
  7. package/dist/generators/common-resources/cloudsql-database/index.js +40 -287
  8. package/dist/generators/common-resources/confluent-cluster/index.js +23 -132
  9. package/dist/generators/common-resources/datastore/index.js +48 -194
  10. package/dist/generators/common-resources/elastic-cloud/index.js +22 -132
  11. package/dist/generators/common-resources/elastic-index-policy/handle-yaml.js +76 -0
  12. package/dist/generators/common-resources/elastic-index-policy/index.js +131 -286
  13. package/dist/generators/common-resources/elastic-template/index.js +52 -162
  14. package/dist/generators/common-resources/firestore/index.js +93 -233
  15. package/dist/generators/common-resources/iam/index.js +35 -157
  16. package/dist/generators/common-resources/iam/valid-prefix.js +8 -0
  17. package/dist/generators/common-resources/kafka-connect/index.js +35 -144
  18. package/dist/generators/common-resources/kafka-topics/index.js +20 -129
  19. package/dist/generators/common-resources/kms/index.js +31 -141
  20. package/dist/generators/common-resources/memorystore/index.js +42 -328
  21. package/dist/generators/common-resources/monitoring/handle-yaml.js +49 -0
  22. package/dist/generators/common-resources/monitoring/index.js +144 -322
  23. package/dist/generators/common-resources/monitoring/validate.js +58 -0
  24. package/dist/generators/common-resources/pubsub/append.js +130 -0
  25. package/dist/generators/common-resources/pubsub/get-gcp-projects.js +34 -0
  26. package/dist/generators/common-resources/pubsub/handle-subscribers.js +68 -0
  27. package/dist/generators/common-resources/pubsub/index.js +194 -536
  28. package/dist/generators/common-resources/pubsub/validate.js +53 -0
  29. package/dist/generators/common-resources/scheduler/append.js +85 -0
  30. package/dist/generators/common-resources/scheduler/index.js +62 -249
  31. package/dist/generators/common-resources/spanner/append.js +31 -0
  32. package/dist/generators/common-resources/spanner/index.js +102 -269
  33. package/dist/generators/common-resources/spanner/validate.js +38 -0
  34. package/dist/generators/docs/rca/index.js +25 -135
  35. package/dist/generators/docs/runbook/index.js +16 -126
  36. package/dist/generators/docs/srb/index.js +33 -147
  37. package/dist/generators/docs/srb/run-docker.js +2 -0
  38. package/dist/generators/init/clan-infra/gcp-projects.js +47 -0
  39. package/dist/generators/init/clan-infra/index.js +95 -290
  40. package/dist/generators/init/clan-infra/tribe-clan-repo.js +38 -0
  41. package/dist/generators/init/clan-infra/validate.js +8 -0
  42. package/dist/generators/maintenance/manage-states/index.js +142 -219
  43. package/dist/generators/maintenance/update-modules/index.js +56 -155
  44. package/dist/generators/organization/clan-project/googlecloud.js +124 -0
  45. package/dist/generators/organization/clan-project/index.js +81 -303
  46. package/dist/node_modules/.package-lock.json +81 -23
  47. package/dist/package.json +45 -0
  48. package/dist/src/BaseGenerator.js +84 -0
  49. package/dist/src/SecretsGenerator.js +137 -0
  50. package/dist/src/cli.js +54 -255
  51. package/dist/src/dependency-check.js +48 -0
  52. package/dist/src/update-check.js +38 -0
  53. package/dist/src/validators.js +33 -0
  54. package/dist/src/yeoman.js +80 -0
  55. package/package.json +1 -2
@@ -1,238 +1,137 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropNames = Object.getOwnPropertyNames;
3
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
4
- var __commonJS = (cb, mod) => function __require() {
5
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
6
- };
7
-
8
- // src/validators.js
9
- var require_validators = __commonJS({
10
- "src/validators.js"(exports2, module2) {
11
- var path2 = require("path");
12
- module2.exports = {
13
- chain: /* @__PURE__ */ __name((input, ...validators) => {
14
- let msg = "";
15
- validators.every((validator) => {
16
- msg = validator(input);
17
- return msg === true;
18
- });
19
- return msg === true ? true : msg;
20
- }, "chain"),
21
- filename: /* @__PURE__ */ __name((input) => {
22
- if (!input) {
23
- return true;
24
- }
25
- return path2.basename(input) === input ? true : "Invalid filename";
26
- }, "filename"),
27
- maxLength: /* @__PURE__ */ __name((input, maxLength) => !input || input.length <= maxLength ? true : `Exceeds max \
28
- length: ${maxLength}`, "maxLength"),
29
- required: /* @__PURE__ */ __name((input) => {
30
- const msg = "Required";
31
- if (Array.isArray(input)) {
32
- return input.length > 0 ? true : msg;
33
- }
34
- if (input) {
35
- return input.trim().length > 0 ? true : msg;
36
- }
37
- return msg;
38
- }, "required")
39
- };
40
- }
41
- });
42
-
43
- // src/BaseGenerator.js
44
- var require_BaseGenerator = __commonJS({
45
- "src/BaseGenerator.js"(exports2, module2) {
46
- var Generator = require("yeoman-generator");
47
- var path2 = require("path");
48
- var fs2 = require("fs");
49
- var inquirer = require("inquirer");
50
- var { chain, required: required2, filename } = require_validators();
51
- module2.exports = class extends Generator {
52
- constructor(args, opts) {
53
- super(args, opts);
54
- this.baseDir = path2.resolve(path2.join(__dirname, ".."));
55
- this.destinationRoot(process.cwd());
56
- const [command, generator] = opts.namespace.split(":").slice(-2);
57
- this.generatorId = path2.join(command, generator);
58
- this.sourceRoot(
59
- path2.join(this.baseDir, "generators", this.generatorId, "templates")
60
- );
61
- this.copyDir = (templateDir, targetDir, answers = this.answers, skipIfExists = false) => {
62
- if (skipIfExists && fs2.existsSync(targetDir)) {
63
- return;
64
- }
65
- this.fs.copyTpl(
66
- this.templatePath(`${templateDir}/**/*`),
67
- this.destinationPath(targetDir),
68
- answers
69
- );
70
- };
71
- this.listSubDirectories = (parent) => fs2.readdirSync(parent).filter((f) => !f.startsWith(".")).filter((f) => fs2.
72
- lstatSync(path2.join(parent, f)).isDirectory()).sort((a, b) => a.localeCompare(b));
73
- this.kebabCase = (input) => input.replace(/\s|_/g, "-");
74
- this.chooseOrCreatePrompts = (name, getChoicesDirectory) => [
75
- {
76
- when: /* @__PURE__ */ __name((answers) => fs2.existsSync(getChoicesDirectory(answers)), "when"),
77
- type: "list",
78
- name,
79
- message: `Choose ${name}`,
80
- store: true,
81
- choices: /* @__PURE__ */ __name((answers) => [
82
- ...this.listSubDirectories(getChoicesDirectory(answers)),
83
- new inquirer.Separator(),
84
- `Create new ${name}`
85
- ], "choices"),
86
- validate: required2,
87
- filter: this.kebabCase
88
- },
89
- {
90
- when: /* @__PURE__ */ __name((answers) => !fs2.existsSync(getChoicesDirectory(answers)) || answers[name] ===
91
- `Create-new-${name}`, "when"),
92
- type: "input",
93
- name: `new-${name}`,
94
- message: `New ${name} name`,
95
- store: false,
96
- validate: /* @__PURE__ */ __name((input) => chain(input, required2, filename), "validate"),
97
- filter: this.kebabCase
98
- },
99
- {
100
- when: /* @__PURE__ */ __name((answers) => !fs2.existsSync(getChoicesDirectory(answers)) || answers[name] ===
101
- "Create-new-tribe", "when"),
102
- type: "input",
103
- name: "costCenter",
104
- message: "Please provide the Cost Center of the Tribe",
105
- store: false,
106
- validate: /* @__PURE__ */ __name((input) => chain(input, required2, filename), "validate"),
107
- filter: this.kebabCase
108
- }
109
- ];
110
- }
111
- };
112
- }
113
- });
1
+ const path = require('path');
2
+ const fs = require('fs');
3
+ const chalk = require('chalk');
4
+ const BaseGenerator = require('../../../src/BaseGenerator');
5
+ const { required } = require('../../../src/validators');
114
6
 
115
- // generators/clan-resources/clan-project/index.js
116
- var path = require("path");
117
- var fs = require("fs");
118
- var chalk = require("chalk");
119
- var BaseGenerator = require_BaseGenerator();
120
- var { required } = require_validators();
121
7
  module.exports = class extends BaseGenerator {
122
8
  constructor(args, opts) {
123
9
  super(args, opts);
124
- this.destinationRoot("organization");
10
+
11
+ // Output directory relative to the tf-infra-gcp directory.
12
+ this.destinationRoot('organization');
125
13
  }
14
+
126
15
  prompting() {
127
16
  const prompts = [
128
17
  {
129
- type: "list",
130
- name: "domain",
131
- default: "extendaretail-com",
132
- message: "Choose GCP Organization",
18
+ type: 'list',
19
+ name: 'domain',
20
+ default: 'extendaretail-com',
21
+ message: 'Choose GCP Organization',
133
22
  store: true,
134
23
  choices: this.listSubDirectories(this.destinationPath()),
135
- validate: required
24
+ validate: required,
136
25
  },
137
26
  {
138
- type: "list",
139
- name: "department",
140
- message: "Choose department",
27
+ type: 'list',
28
+ name: 'department',
29
+ message: 'Choose department',
141
30
  store: true,
142
- choices: /* @__PURE__ */ __name((answers) => this.listSubDirectories(
143
- path.join(this.destinationPath(), answers.domain, "departments")
144
- ), "choices"),
145
- validate: required
31
+ choices: (answers) =>
32
+ this.listSubDirectories(
33
+ path.join(this.destinationPath(), answers.domain, 'departments'),
34
+ ),
35
+ validate: required,
146
36
  },
147
37
  {
148
- type: "list",
149
- name: "tribe",
150
- message: "Choose tribe",
38
+ type: 'list',
39
+ name: 'tribe',
40
+ message: 'Choose tribe',
151
41
  store: true,
152
- choices: /* @__PURE__ */ __name((answers) => this.listSubDirectories(
153
- path.join(
154
- this.destinationPath(),
155
- answers.domain,
156
- "departments",
157
- answers.department
158
- )
159
- ), "choices"),
160
- validate: required
42
+ choices: (answers) =>
43
+ this.listSubDirectories(
44
+ path.join(
45
+ this.destinationPath(),
46
+ answers.domain,
47
+ 'departments',
48
+ answers.department,
49
+ ),
50
+ ),
51
+ validate: required,
161
52
  },
162
53
  {
163
- type: "list",
164
- name: "clan",
165
- message: "Choose clan",
54
+ type: 'list',
55
+ name: 'clan',
56
+ message: 'Choose clan',
166
57
  store: true,
167
- choices: /* @__PURE__ */ __name((answers) => this.listSubDirectories(
168
- path.join(
169
- this.destinationPath(),
170
- answers.domain,
171
- "departments",
172
- answers.department,
173
- answers.tribe,
174
- "clans"
175
- )
176
- ), "choices"),
177
- validate: required
58
+ choices: (answers) =>
59
+ this.listSubDirectories(
60
+ path.join(
61
+ this.destinationPath(),
62
+ answers.domain,
63
+ 'departments',
64
+ answers.department,
65
+ answers.tribe,
66
+ 'clans',
67
+ ),
68
+ ),
69
+ validate: required,
178
70
  },
179
71
  {
180
- type: "list",
181
- name: "migration",
182
- message: "Is the project in the process of migration to Autopilot?",
183
- default: "yes",
184
- choices: ["yes", "no"]
185
- }
72
+ type: 'list',
73
+ name: 'migration',
74
+ message: 'Is the project in the process of migration to Autopilot?',
75
+ default: 'yes',
76
+ choices: ['yes', 'no'],
77
+ },
186
78
  ];
79
+
187
80
  return this.prompt(prompts).then((props) => {
188
81
  this.answers = props;
189
82
  });
190
83
  }
84
+
191
85
  writing() {
192
86
  const { domain, department, tribe, clan, migration } = this.answers;
193
- ["prod", "staging"].forEach((env) => {
87
+
88
+ ['prod', 'staging'].forEach((env) => {
194
89
  this.copyDir(
195
- "clan-resources",
90
+ 'clan-resources',
196
91
  path.join(
197
92
  domain,
198
- "departments",
93
+ 'departments',
199
94
  department,
200
95
  tribe,
201
- "clans",
96
+ 'clans',
202
97
  clan,
203
98
  env,
204
- "resources"
99
+ 'resources',
205
100
  ),
206
101
  {
207
102
  ...this.answers,
208
- env
209
- }
103
+ env,
104
+ },
210
105
  );
211
106
  });
212
- if (migration === "yes") {
213
- ["prod", "staging"].forEach((env) => {
107
+
108
+ if (migration === 'yes') {
109
+ ['prod', 'staging'].forEach((env) => {
214
110
  const terragruntFilePath = path.join(
215
111
  domain,
216
- "departments",
112
+ 'departments',
217
113
  department,
218
114
  tribe,
219
- "clans",
115
+ 'clans',
220
116
  clan,
221
117
  env,
222
- "terragrunt.hcl"
118
+ 'terragrunt.hcl',
223
119
  );
224
- fs.readFile(terragruntFilePath, "utf8", (err, data) => {
120
+
121
+ fs.readFile(terragruntFilePath, 'utf8', (err, data) => {
225
122
  if (err) {
226
123
  return;
227
124
  }
125
+
228
126
  const modifiedData = data.replace(
229
127
  /source\s*=\s*"git::https:\/\/github\.com\/extenda\/tf-module-gcp-project\/\/\?ref=.+"/,
230
- 'source = "git::https://github.com/extenda/tf-module-gcp-project//?ref=migration"'
128
+ 'source = "git::https://github.com/extenda/tf-module-gcp-project//?ref=migration"',
231
129
  );
232
- fs.writeFile(terragruntFilePath, modifiedData, "utf8", (error) => {
130
+
131
+ fs.writeFile(terragruntFilePath, modifiedData, 'utf8', (error) => {
233
132
  if (error) {
234
133
  console.error(
235
- `Error writing file ${terragruntFilePath}: ${error.message}`
134
+ `Error writing file ${terragruntFilePath}: ${error.message}`,
236
135
  );
237
136
  } else {
238
137
  console.log(`Updated file ${terragruntFilePath}`);
@@ -242,25 +141,26 @@ module.exports = class extends BaseGenerator {
242
141
  });
243
142
  }
244
143
  }
144
+
245
145
  end() {
246
146
  const { domain, department, tribe, clan } = this.answers;
247
147
  const clanDir = path.join(
248
148
  domain,
249
- "departments",
149
+ 'departments',
250
150
  department,
251
151
  tribe,
252
- "clans",
253
- clan
152
+ 'clans',
153
+ clan,
254
154
  );
255
155
  this.log(`
256
156
  ${chalk.green(`Your clan resources have now been created. To finalize your configuration, please continue
257
157
  with manual editing of the generated files.`)}
258
- ${chalk.green("1.")} Review the configurations
259
- \u2192 ${chalk.cyan(path.join(clanDir, "prod", "network", "spec.hcl"))}
260
- \u2192 ${chalk.cyan(path.join(clanDir, "prod", "gke", "spec.hcl"))}
261
- \u2192 ${chalk.cyan(path.join(clanDir, "staging", "network", "spec.hcl"))}
262
- \u2192 ${chalk.cyan(path.join(clanDir, "staging", "gke", "spec.hcl"))}
263
- ${chalk.green("2.")} Push this change in a feature branch and open a pull request.
158
+ ${chalk.green('1.')} Review the configurations
159
+ \u2192 ${chalk.cyan(path.join(clanDir, 'prod', 'network', 'spec.hcl'))}
160
+ \u2192 ${chalk.cyan(path.join(clanDir, 'prod', 'gke', 'spec.hcl'))}
161
+ \u2192 ${chalk.cyan(path.join(clanDir, 'staging', 'network', 'spec.hcl'))}
162
+ \u2192 ${chalk.cyan(path.join(clanDir, 'staging', 'gke', 'spec.hcl'))}
163
+ ${chalk.green('2.')} Push this change in a feature branch and open a pull request.
264
164
  `);
265
165
  }
266
166
  };