@hiiretail/gcp-infra-generators 1.0.2 → 1.1.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.
- package/dist/generators/common-resources/pubsub/index.js +46 -9
- package/dist/generators/common-resources/pubsub/templates/pubsub-external-publishers/bindings.yaml +8 -0
- package/dist/generators/common-resources/pubsub/templates/pubsub-external-publishers/terragrunt.hcl +37 -0
- package/dist/node_modules/.package-lock.json +377 -377
- package/dist/package.json +1 -1
- package/package.json +1 -1
|
@@ -18,7 +18,7 @@ module.exports = class extends BaseGenerator {
|
|
|
18
18
|
{
|
|
19
19
|
type: 'list',
|
|
20
20
|
name: 'createResource',
|
|
21
|
-
message: 'Do you want to create a new topic
|
|
21
|
+
message: 'Do you want to create a new topic, subscription?',
|
|
22
22
|
default: 'subscription',
|
|
23
23
|
choices: ['topic', 'subscription'],
|
|
24
24
|
},
|
|
@@ -168,6 +168,15 @@ module.exports = class extends BaseGenerator {
|
|
|
168
168
|
'Please provide the audience that will be used when generating OIDC token',
|
|
169
169
|
validate: required,
|
|
170
170
|
},
|
|
171
|
+
{
|
|
172
|
+
when: (response) => response.createResource === 'topic',
|
|
173
|
+
type: 'list',
|
|
174
|
+
name: 'externalTopicPublishers',
|
|
175
|
+
message: 'Do you want to allow external publishers onto this topic?',
|
|
176
|
+
default: 'no',
|
|
177
|
+
choices: ['no', 'yes'],
|
|
178
|
+
validate: required,
|
|
179
|
+
},
|
|
171
180
|
];
|
|
172
181
|
|
|
173
182
|
return this.prompt(prompts).then((props) => {
|
|
@@ -195,6 +204,7 @@ module.exports = class extends BaseGenerator {
|
|
|
195
204
|
prodProjectIdConsumer,
|
|
196
205
|
costCenter,
|
|
197
206
|
externalSub,
|
|
207
|
+
externalTopicPublishers,
|
|
198
208
|
} = this.answers;
|
|
199
209
|
|
|
200
210
|
const dlqTopicName = `dlq.${getProjectId('prod').split('-prod')[0]}.common`;
|
|
@@ -224,7 +234,8 @@ module.exports = class extends BaseGenerator {
|
|
|
224
234
|
'pubsub',
|
|
225
235
|
topicName,
|
|
226
236
|
);
|
|
227
|
-
['terragrunt.hcl', 'spec.hcl']
|
|
237
|
+
const files = ['terragrunt.hcl', 'spec.hcl'];
|
|
238
|
+
for (const file of files) {
|
|
228
239
|
this.fs.copyTpl(
|
|
229
240
|
this.templatePath(`pubsub/${file}`),
|
|
230
241
|
this.destinationPath(`${topicDirPath}/${file}`),
|
|
@@ -236,7 +247,7 @@ module.exports = class extends BaseGenerator {
|
|
|
236
247
|
dlqTopic,
|
|
237
248
|
},
|
|
238
249
|
);
|
|
239
|
-
}
|
|
250
|
+
}
|
|
240
251
|
}
|
|
241
252
|
|
|
242
253
|
let projectId = getProjectId(env);
|
|
@@ -276,7 +287,8 @@ module.exports = class extends BaseGenerator {
|
|
|
276
287
|
);
|
|
277
288
|
}
|
|
278
289
|
|
|
279
|
-
['terragrunt.hcl', 'spec.hcl']
|
|
290
|
+
const files = ['terragrunt.hcl', 'spec.hcl'];
|
|
291
|
+
for (const file of files) {
|
|
280
292
|
this.fs.copyTpl(
|
|
281
293
|
this.templatePath(`pubsub/${file}`),
|
|
282
294
|
this.destinationPath(`${subscriptionDirPath}/${file}`),
|
|
@@ -286,7 +298,7 @@ module.exports = class extends BaseGenerator {
|
|
|
286
298
|
existingTopic,
|
|
287
299
|
},
|
|
288
300
|
);
|
|
289
|
-
}
|
|
301
|
+
}
|
|
290
302
|
|
|
291
303
|
await handleSubscribers(
|
|
292
304
|
env,
|
|
@@ -297,11 +309,12 @@ module.exports = class extends BaseGenerator {
|
|
|
297
309
|
dlqTopic,
|
|
298
310
|
);
|
|
299
311
|
}
|
|
312
|
+
|
|
300
313
|
if (createResource === 'subscription' && externalSub === 'yes') {
|
|
301
314
|
const externalDirPath = path.join(
|
|
302
315
|
process.cwd(),
|
|
303
316
|
'infra',
|
|
304
|
-
|
|
317
|
+
env,
|
|
305
318
|
'pubsub',
|
|
306
319
|
existingTopic,
|
|
307
320
|
`${clanName}-${env}`,
|
|
@@ -311,7 +324,8 @@ module.exports = class extends BaseGenerator {
|
|
|
311
324
|
fs.mkdirSync(externalDirPath);
|
|
312
325
|
}
|
|
313
326
|
|
|
314
|
-
['terragrunt.hcl', 'spec.hcl']
|
|
327
|
+
const files = ['terragrunt.hcl', 'spec.hcl'];
|
|
328
|
+
for (const file of files) {
|
|
315
329
|
this.fs.copyTpl(
|
|
316
330
|
this.templatePath(`pubsub-external/${file}`),
|
|
317
331
|
this.destinationPath(`${externalDirPath}/${file}`),
|
|
@@ -326,7 +340,7 @@ module.exports = class extends BaseGenerator {
|
|
|
326
340
|
projectId,
|
|
327
341
|
},
|
|
328
342
|
);
|
|
329
|
-
}
|
|
343
|
+
}
|
|
330
344
|
|
|
331
345
|
const externalSubPath = `${externalDirPath}/subscribers.yaml`;
|
|
332
346
|
if (env === 'staging') {
|
|
@@ -362,6 +376,28 @@ module.exports = class extends BaseGenerator {
|
|
|
362
376
|
dlqTopic,
|
|
363
377
|
);
|
|
364
378
|
}
|
|
379
|
+
|
|
380
|
+
if (createResource === 'topic' && externalTopicPublishers === 'yes') {
|
|
381
|
+
const externalPublishersPath = path.join(
|
|
382
|
+
process.cwd(),
|
|
383
|
+
'infra',
|
|
384
|
+
env,
|
|
385
|
+
'pubsub',
|
|
386
|
+
topicName,
|
|
387
|
+
'external-publishers',
|
|
388
|
+
);
|
|
389
|
+
|
|
390
|
+
const files = ['terragrunt.hcl', 'bindings.yaml'];
|
|
391
|
+
for (const file of files) {
|
|
392
|
+
this.fs.copyTpl(
|
|
393
|
+
this.templatePath(`pubsub-external-publishers/${file}`),
|
|
394
|
+
this.destinationPath(`${externalPublishersPath}/${file}`),
|
|
395
|
+
{
|
|
396
|
+
...this.answers,
|
|
397
|
+
},
|
|
398
|
+
);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
365
401
|
});
|
|
366
402
|
}
|
|
367
403
|
|
|
@@ -370,7 +406,8 @@ module.exports = class extends BaseGenerator {
|
|
|
370
406
|
${chalk.green(`Your PubSub resources have now been created. To finalize your configuration, please continue
|
|
371
407
|
with manual editing of the generated files.`)}
|
|
372
408
|
${chalk.green('1.')} Review created subscribers.
|
|
373
|
-
${chalk.green('2.')}
|
|
409
|
+
${chalk.green('2.')} Review created external publishers.
|
|
410
|
+
${chalk.green('3.')} Push this change in a feature branch and open a pull request.
|
|
374
411
|
`);
|
|
375
412
|
}
|
|
376
413
|
};
|
package/dist/generators/common-resources/pubsub/templates/pubsub-external-publishers/terragrunt.hcl
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Terragrunt will copy the Terraform configurations specified by the source parameter, along with any files in the
|
|
2
|
+
# working directory, into a temporary folder, and execute your Terraform commands in that folder.
|
|
3
|
+
terraform {
|
|
4
|
+
source = "git::https://github.com/terraform-google-modules/terraform-google-iam.git//modules/pubsub_topics_iam?ref=v8.1.0"
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
include {
|
|
8
|
+
path = find_in_parent_folders("terragrunt_root.hcl")
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
locals {
|
|
12
|
+
project_vars = read_terragrunt_config(find_in_parent_folders("project.hcl"))
|
|
13
|
+
bindings_raw = yamldecode(file("${get_terragrunt_dir()}/bindings.yaml"))
|
|
14
|
+
clan_members = flatten([
|
|
15
|
+
for clan, members in local.bindings_raw.clans : [
|
|
16
|
+
for m in members : (
|
|
17
|
+
can(m.serviceAccount) ? m.serviceAccount : regex_replace("^serviceAccount:", "", m)
|
|
18
|
+
)
|
|
19
|
+
]
|
|
20
|
+
])
|
|
21
|
+
|
|
22
|
+
iam_bindings = {
|
|
23
|
+
"roles/pubsub.publisher" = [
|
|
24
|
+
for sa in local.clan_members : "serviceAccount:${sa}"
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
dependency "topic" {
|
|
30
|
+
config_path = "../"
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
inputs = {
|
|
34
|
+
project = local.project_vars.locals.project_id
|
|
35
|
+
pubsub_topics = [dependency.topic.outputs.topic]
|
|
36
|
+
bindings = local.iam_bindings
|
|
37
|
+
}
|