@hiiretail/gcp-infra-cli 0.104.0 → 1.0.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.
Files changed (217) hide show
  1. package/README.md +9 -46
  2. package/bin/gcp-infra +5 -2
  3. package/package.json +7 -30
  4. package/src/gcp-infra.js +87 -0
  5. package/LICENSE +0 -21
  6. package/generators/clan-resources/clan-project/generator.json +0 -4
  7. package/generators/clan-resources/clan-project/index.js +0 -135
  8. package/generators/clan-resources/clan-project/templates/clan-resources/cloud-nat/terragrunt.hcl +0 -52
  9. package/generators/clan-resources/clan-project/templates/clan-resources/cloud-nat-static-ip/spec.hcl +0 -7
  10. package/generators/clan-resources/clan-project/templates/clan-resources/cloud-nat-static-ip/terragrunt.hcl +0 -25
  11. package/generators/clan-resources/clan-project/templates/clan-resources/cloud-router/terragrunt.hcl +0 -34
  12. package/generators/clan-resources/clan-project/templates/clan-resources/gke/gke-resources/terragrunt.hcl +0 -40
  13. package/generators/clan-resources/clan-project/templates/clan-resources/gke/spec.hcl +0 -18
  14. package/generators/clan-resources/clan-project/templates/clan-resources/gke/terragrunt.hcl +0 -52
  15. package/generators/clan-resources/clan-project/templates/clan-resources/network/firewall-rules/config/main.tf +0 -41
  16. package/generators/clan-resources/clan-project/templates/clan-resources/network/firewall-rules/config/vars.tf +0 -9
  17. package/generators/clan-resources/clan-project/templates/clan-resources/network/firewall-rules/terragrunt.hcl +0 -32
  18. package/generators/clan-resources/clan-project/templates/clan-resources/network/spec.hcl +0 -54
  19. package/generators/clan-resources/clan-project/templates/clan-resources/network/terragrunt.hcl +0 -29
  20. package/generators/clan-resources/clan-project/templates/clan-resources/private-vpc-connection/config/main.tf +0 -18
  21. package/generators/clan-resources/clan-project/templates/clan-resources/private-vpc-connection/config/vars.tf +0 -27
  22. package/generators/clan-resources/clan-project/templates/clan-resources/private-vpc-connection/terragrunt.hcl +0 -35
  23. package/generators/clan-resources/clan-project/templates/clan-resources/serverless-vpc-connector/terragrunt.hcl +0 -40
  24. package/generators/clan-resources/clan-project/templates/clan-resources/terragrunt.hcl +0 -3
  25. package/generators/clan-resources/command.json +0 -7
  26. package/generators/common-resources/bigquery/generator.json +0 -4
  27. package/generators/common-resources/bigquery/index.js +0 -284
  28. package/generators/common-resources/bigquery/templates/bigquery/spec.hcl +0 -8
  29. package/generators/common-resources/bigquery/templates/bigquery/terragrunt.hcl +0 -53
  30. package/generators/common-resources/bigquery/templates/scheduled-queries/terragrunt.hcl +0 -56
  31. package/generators/common-resources/bigquery/templates/schema/schema.json +0 -14
  32. package/generators/common-resources/budget/generator.json +0 -4
  33. package/generators/common-resources/budget/index.js +0 -89
  34. package/generators/common-resources/budget/templates/budget/terragrunt.hcl +0 -45
  35. package/generators/common-resources/cloud-armor/generator.json +0 -4
  36. package/generators/common-resources/cloud-armor/index.js +0 -45
  37. package/generators/common-resources/cloud-armor/templates/policies.yaml +0 -53
  38. package/generators/common-resources/cloud-armor/templates/terragrunt.hcl +0 -30
  39. package/generators/common-resources/cloud-storage/generator.json +0 -4
  40. package/generators/common-resources/cloud-storage/index.js +0 -156
  41. package/generators/common-resources/cloud-storage/templates/cloud-storage/storage.yaml +0 -26
  42. package/generators/common-resources/cloud-storage/templates/cloud-storage/terragrunt.hcl +0 -32
  43. package/generators/common-resources/cloudsql/generator.json +0 -4
  44. package/generators/common-resources/cloudsql/index.js +0 -106
  45. package/generators/common-resources/cloudsql/templates/mssql/instance/spec.hcl +0 -76
  46. package/generators/common-resources/cloudsql/templates/mssql/instance/terragrunt.hcl +0 -38
  47. package/generators/common-resources/cloudsql/templates/mssql/instance-secrets/terragrunt.hcl +0 -37
  48. package/generators/common-resources/cloudsql/templates/mysql/instance/spec.hcl +0 -73
  49. package/generators/common-resources/cloudsql/templates/mysql/instance/terragrunt.hcl +0 -40
  50. package/generators/common-resources/cloudsql/templates/mysql/instance-secrets/terragrunt.hcl +0 -38
  51. package/generators/common-resources/cloudsql/templates/postgres-clan/instance/spec.hcl +0 -102
  52. package/generators/common-resources/cloudsql/templates/postgres-clan/instance/terragrunt.hcl +0 -36
  53. package/generators/common-resources/cloudsql/templates/postgres-clan/instance-secrets/terragrunt.hcl +0 -44
  54. package/generators/common-resources/cloudsql-database/generator.json +0 -4
  55. package/generators/common-resources/cloudsql-database/index.js +0 -70
  56. package/generators/common-resources/cloudsql-database/templates/mysql/database/proxy_port.hcl +0 -4
  57. package/generators/common-resources/cloudsql-database/templates/mysql/database/terragrunt.hcl +0 -69
  58. package/generators/common-resources/cloudsql-database/templates/mysql/outputs.json +0 -5
  59. package/generators/common-resources/cloudsql-database/templates/mysql/secrets/terragrunt.hcl +0 -30
  60. package/generators/common-resources/cloudsql-database/templates/postgres/database/proxy_port.hcl +0 -4
  61. package/generators/common-resources/cloudsql-database/templates/postgres/database/spec.hcl +0 -17
  62. package/generators/common-resources/cloudsql-database/templates/postgres/database/terragrunt.hcl +0 -74
  63. package/generators/common-resources/cloudsql-database/templates/postgres/outputs.json +0 -5
  64. package/generators/common-resources/cloudsql-database/templates/postgres/secrets/terragrunt.hcl +0 -30
  65. package/generators/common-resources/command.json +0 -8
  66. package/generators/common-resources/confluent-cluster/generator.json +0 -4
  67. package/generators/common-resources/confluent-cluster/index.js +0 -52
  68. package/generators/common-resources/confluent-cluster/templates/confluent/spec.hcl +0 -5
  69. package/generators/common-resources/confluent-cluster/templates/confluent/terragrunt.hcl +0 -25
  70. package/generators/common-resources/datastore/generator.json +0 -4
  71. package/generators/common-resources/datastore/index.js +0 -91
  72. package/generators/common-resources/datastore/templates/datastore/indexes.yaml +0 -6
  73. package/generators/common-resources/datastore/templates/datastore/terragrunt.hcl +0 -23
  74. package/generators/common-resources/elastic-cloud/generator.json +0 -4
  75. package/generators/common-resources/elastic-cloud/index.js +0 -52
  76. package/generators/common-resources/elastic-cloud/templates/elastic/spec.hcl +0 -27
  77. package/generators/common-resources/elastic-cloud/templates/elastic/terragrunt.hcl +0 -27
  78. package/generators/common-resources/elastic-index-policy/generator.json +0 -4
  79. package/generators/common-resources/elastic-index-policy/handle-yaml.js +0 -76
  80. package/generators/common-resources/elastic-index-policy/index.js +0 -210
  81. package/generators/common-resources/elastic-index-policy/templates/policy/policy.yaml +0 -28
  82. package/generators/common-resources/elastic-index-policy/templates/policy/terragrunt.hcl +0 -25
  83. package/generators/common-resources/elastic-template/generator.json +0 -4
  84. package/generators/common-resources/elastic-template/index.js +0 -84
  85. package/generators/common-resources/elastic-template/templates/elastic-template/mappings.json +0 -1
  86. package/generators/common-resources/elastic-template/templates/elastic-template/terragrunt.hcl +0 -35
  87. package/generators/common-resources/firestore/generator.json +0 -4
  88. package/generators/common-resources/firestore/index.js +0 -141
  89. package/generators/common-resources/firestore/templates/firestore/indexes/indexes.yaml +0 -12
  90. package/generators/common-resources/firestore/templates/firestore/indexes/terragrunt.hcl +0 -27
  91. package/generators/common-resources/firestore/templates/firestore/spec.hcl +0 -31
  92. package/generators/common-resources/firestore/templates/firestore/terragrunt.hcl +0 -25
  93. package/generators/common-resources/iam/generator.json +0 -4
  94. package/generators/common-resources/iam/index.js +0 -62
  95. package/generators/common-resources/iam/templates/github/workflows/iam.yml +0 -18
  96. package/generators/common-resources/iam/templates/iam.yaml +0 -8
  97. package/generators/common-resources/iam/valid-prefix.js +0 -8
  98. package/generators/common-resources/kafka-connect/generator.json +0 -4
  99. package/generators/common-resources/kafka-connect/index.js +0 -75
  100. package/generators/common-resources/kafka-connect/templates/elastic/terragrunt.hcl +0 -92
  101. package/generators/common-resources/kafka-connect/templates/pubsub/terragrunt.hcl +0 -75
  102. package/generators/common-resources/kafka-topics/generator.json +0 -4
  103. package/generators/common-resources/kafka-topics/index.js +0 -54
  104. package/generators/common-resources/kafka-topics/templates/kafka/kafka.yaml +0 -20
  105. package/generators/common-resources/kafka-topics/templates/kafka/terragrunt.hcl +0 -21
  106. package/generators/common-resources/kms/generator.json +0 -4
  107. package/generators/common-resources/kms/index.js +0 -69
  108. package/generators/common-resources/kms/templates/kms/spec.hcl +0 -5
  109. package/generators/common-resources/kms/templates/kms/terragrunt.hcl +0 -33
  110. package/generators/common-resources/memorystore/generator.json +0 -4
  111. package/generators/common-resources/memorystore/index.js +0 -69
  112. package/generators/common-resources/memorystore/templates/outputs.json +0 -3
  113. package/generators/common-resources/memorystore/templates/redis-instance/spec.hcl +0 -16
  114. package/generators/common-resources/memorystore/templates/redis-instance/terragrunt.hcl +0 -35
  115. package/generators/common-resources/memorystore/templates/secrets/terragrunt.hcl +0 -31
  116. package/generators/common-resources/monitoring/generator.json +0 -4
  117. package/generators/common-resources/monitoring/handle-yaml.js +0 -48
  118. package/generators/common-resources/monitoring/index.js +0 -192
  119. package/generators/common-resources/monitoring/templates/alerts/generic-infra.yaml +0 -633
  120. package/generators/common-resources/monitoring/templates/alerts/terragrunt.hcl +0 -37
  121. package/generators/common-resources/monitoring/templates/service/service.yaml +0 -16
  122. package/generators/common-resources/monitoring/templates/service/terragrunt.hcl +0 -37
  123. package/generators/common-resources/monitoring/templates/uptime-checks/terragrunt.hcl +0 -36
  124. package/generators/common-resources/monitoring/templates/uptime-checks/uptime-checks.yaml +0 -3
  125. package/generators/common-resources/monitoring/validate.js +0 -58
  126. package/generators/common-resources/pubsub/append.js +0 -120
  127. package/generators/common-resources/pubsub/generator.json +0 -4
  128. package/generators/common-resources/pubsub/get-gcp-projects.js +0 -34
  129. package/generators/common-resources/pubsub/handle-subscribers.js +0 -63
  130. package/generators/common-resources/pubsub/index.js +0 -316
  131. package/generators/common-resources/pubsub/templates/pubsub/spec.hcl +0 -7
  132. package/generators/common-resources/pubsub/templates/pubsub/subscribers.yaml +0 -16
  133. package/generators/common-resources/pubsub/templates/pubsub/terragrunt.hcl +0 -34
  134. package/generators/common-resources/pubsub/templates/pubsub-dlq/terragrunt.hcl +0 -42
  135. package/generators/common-resources/pubsub/templates/pubsub-external/spec.hcl +0 -10
  136. package/generators/common-resources/pubsub/templates/pubsub-external/subscribers.yaml +0 -16
  137. package/generators/common-resources/pubsub/templates/pubsub-external/terragrunt.hcl +0 -31
  138. package/generators/common-resources/pubsub/validate.js +0 -44
  139. package/generators/common-resources/scheduler/append.js +0 -83
  140. package/generators/common-resources/scheduler/generator.json +0 -4
  141. package/generators/common-resources/scheduler/index.js +0 -103
  142. package/generators/common-resources/scheduler/templates/scheduler/terragrunt.hcl +0 -44
  143. package/generators/common-resources/spanner/append.js +0 -27
  144. package/generators/common-resources/spanner/generator.json +0 -4
  145. package/generators/common-resources/spanner/index.js +0 -169
  146. package/generators/common-resources/spanner/templates/spanner/databases.yaml +0 -5
  147. package/generators/common-resources/spanner/templates/spanner/spec.hcl +0 -22
  148. package/generators/common-resources/spanner/templates/spanner/terragrunt.hcl +0 -33
  149. package/generators/common-resources/spanner/validate.js +0 -38
  150. package/generators/docs/command.json +0 -7
  151. package/generators/docs/rca/generator.json +0 -4
  152. package/generators/docs/rca/index.js +0 -50
  153. package/generators/docs/rca/templates/docs/rca_external.md +0 -43
  154. package/generators/docs/rca/templates/docs/rca_internal.md +0 -88
  155. package/generators/docs/runbook/generator.json +0 -4
  156. package/generators/docs/runbook/index.js +0 -42
  157. package/generators/docs/runbook/templates/docs/runbook.md +0 -106
  158. package/generators/docs/srb/generator.json +0 -4
  159. package/generators/docs/srb/index.js +0 -62
  160. package/generators/docs/srb/templates/docs/README.md +0 -42
  161. package/generators/docs/srb/templates/docs/adr.cmd +0 -3
  162. package/generators/docs/srb/templates/docs/adr.sh +0 -4
  163. package/generators/docs/srb/templates/docs/architecture.md +0 -68
  164. package/generators/docs/srb/templates/docs/cost-estimates.md +0 -39
  165. package/generators/docs/srb/templates/docs/dsl2png.cmd +0 -3
  166. package/generators/docs/srb/templates/docs/dsl2png.sh +0 -4
  167. package/generators/docs/srb/templates/docs/sre.md +0 -43
  168. package/generators/docs/srb/templates/sample.dsl +0 -36
  169. package/generators/init/clan-infra/gcp-projects.js +0 -36
  170. package/generators/init/clan-infra/generator.json +0 -4
  171. package/generators/init/clan-infra/index.js +0 -170
  172. package/generators/init/clan-infra/templates/.yamllint +0 -17
  173. package/generators/init/clan-infra/templates/env/project.hcl +0 -15
  174. package/generators/init/clan-infra/templates/env/secrets/secrets.yaml +0 -4
  175. package/generators/init/clan-infra/templates/env/secrets/terragrunt.hcl +0 -31
  176. package/generators/init/clan-infra/templates/github/CODEOWNERS +0 -1
  177. package/generators/init/clan-infra/templates/github/workflows/infra-verify.yml +0 -16
  178. package/generators/init/clan-infra/templates/github/workflows/infra.yml +0 -17
  179. package/generators/init/clan-infra/templates/github/workflows/release-notes.yml +0 -33
  180. package/generators/init/clan-infra/templates/github/workflows/sync-docs.yml +0 -29
  181. package/generators/init/clan-infra/templates/infra/.terraform-version +0 -1
  182. package/generators/init/clan-infra/templates/infra/.terragrunt-version +0 -1
  183. package/generators/init/clan-infra/templates/infra/README.md +0 -5
  184. package/generators/init/clan-infra/templates/infra/common.hcl +0 -24
  185. package/generators/init/clan-infra/templates/infra/terragrunt_root.hcl +0 -44
  186. package/generators/init/clan-infra/templates/notification-channels/notification-channels.yaml +0 -7
  187. package/generators/init/clan-infra/templates/notification-channels/terragrunt.hcl +0 -29
  188. package/generators/init/clan-infra/templates/release-notes/example-service.yaml +0 -23
  189. package/generators/init/clan-infra/templates/release-notes-schema/release-notes.schema.json +0 -63
  190. package/generators/init/clan-infra/tribe-clan-repo.js +0 -38
  191. package/generators/init/clan-infra/validate.js +0 -8
  192. package/generators/init/command.json +0 -7
  193. package/generators/maintenance/command.json +0 -7
  194. package/generators/maintenance/manage-states/generator.json +0 -4
  195. package/generators/maintenance/manage-states/index.js +0 -188
  196. package/generators/maintenance/update-modules/generator.json +0 -4
  197. package/generators/maintenance/update-modules/index.js +0 -102
  198. package/generators/organization/clan-project/__tests__/__snapshots__/googlecloud.test.js.snap +0 -27
  199. package/generators/organization/clan-project/generator.json +0 -4
  200. package/generators/organization/clan-project/googlecloud.js +0 -119
  201. package/generators/organization/clan-project/index.js +0 -139
  202. package/generators/organization/clan-project/templates/clan/clan.yaml +0 -22
  203. package/generators/organization/clan-project/templates/clan/terragrunt.hcl +0 -39
  204. package/generators/organization/clan-project/templates/clan-project/project.yaml +0 -14
  205. package/generators/organization/clan-project/templates/clan-project/terragrunt.hcl +0 -51
  206. package/generators/organization/clan-project/templates/clans-folder/terragrunt.hcl +0 -3
  207. package/generators/organization/clan-project/templates/department/terragrunt.hcl +0 -32
  208. package/generators/organization/clan-project/templates/tribe/terragrunt.hcl +0 -67
  209. package/generators/organization/clan-project/templates/tribe/tribe.yaml +0 -19
  210. package/generators/organization/command.json +0 -8
  211. package/src/BaseGenerator.js +0 -73
  212. package/src/SecretsGenerator.js +0 -105
  213. package/src/cli.js +0 -73
  214. package/src/dependency-check.js +0 -48
  215. package/src/update-check.js +0 -30
  216. package/src/validators.js +0 -32
  217. package/src/yeoman.js +0 -71
@@ -1,37 +0,0 @@
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/extenda/tf-module-gcp-alert-policy//?ref=v2.0.0"
5
- }
6
-
7
- # Include all settings from the root terragrunt.hcl file
8
- include {
9
- path = find_in_parent_folders("terragrunt_root.hcl")
10
- }
11
-
12
- dependency "notification_channels" {
13
- config_path = "../notification-channels"
14
- mock_outputs = {
15
- notification_channels = ["dummy-channel"]
16
- }
17
- }
18
-
19
- locals {
20
- project_vars = read_terragrunt_config(find_in_parent_folders("project.hcl"))
21
- common_vars = read_terragrunt_config(find_in_parent_folders("common.hcl"))
22
- alerts = flatten([for file in fileset(get_terragrunt_dir(), "./*.yaml") : yamldecode(file(file))])
23
- labels = merge(local.common_vars.locals.default_user_labels, local.project_vars.locals.default_user_labels, {
24
- component = local.common_vars.locals.component
25
- product = local.common_vars.locals.product
26
- tenant-alias = local.common_vars.locals.tenant_alias
27
- })
28
- }
29
-
30
- # These are the variables we have to pass in to use the module specified in the terragrunt configuration above
31
- inputs = {
32
- project = local.project_vars.locals.project_id,
33
- policies = local.alerts,
34
- notification_channel_ids = dependency.notification_channels.outputs.notification_channels,
35
- fallback_notification_channels = dependency.notification_channels.outputs.fallback_channels_ids,
36
- default_user_labels = local.labels,
37
- }
@@ -1,36 +0,0 @@
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/extenda/tf-module-gcp-uptime-check//?ref=v1.0.1"
5
- }
6
-
7
- # Include all settings from the root terragrunt.hcl file
8
- include {
9
- path = find_in_parent_folders("terragrunt_root.hcl")
10
- }
11
-
12
- dependency "notification_channels" {
13
- config_path = "../notification-channels"
14
- mock_outputs = {
15
- notification_channels = ["dummy-channel"]
16
- }
17
- }
18
-
19
- locals {
20
- project_vars = read_terragrunt_config(find_in_parent_folders("project.hcl"))
21
- common_vars = read_terragrunt_config(find_in_parent_folders("common.hcl"))
22
- labels = merge(local.common_vars.locals.default_user_labels, local.project_vars.locals.default_user_labels, {
23
- component = local.common_vars.locals.component
24
- product = local.common_vars.locals.product
25
- tenant-alias = local.common_vars.locals.tenant_alias
26
- })
27
- }
28
-
29
- # These are the variables we have to pass in to use the module specified in the terragrunt configuration above
30
- inputs = {
31
- project = local.project_vars.locals.project_id,
32
- uptime_checks = yamldecode(file("${get_terragrunt_dir()}/uptime-checks.yaml"))
33
- notification_channel_ids = dependency.notification_channels.outputs.notification_channels,
34
- fallback_notification_channels = dependency.notification_channels.outputs.fallback_channels_ids,
35
- default_user_labels = local.labels
36
- }
@@ -1,3 +0,0 @@
1
- service_name: <%-systemName%>.<%-serviceName%>
2
- hostname: <%-hostname%>
3
- path: <%-path%>
@@ -1,58 +0,0 @@
1
- const validate = {};
2
-
3
- const hasWhitespace = (str) => /\s/.test(str);
4
-
5
- const isUrl = (str) => {
6
- try {
7
- return Boolean(new URL(str));
8
- } catch (error) {
9
- return false;
10
- }
11
- };
12
-
13
- validate.clan = (input) => {
14
- if (!hasWhitespace(input)) return true;
15
- return 'Clan name must not include spaces';
16
- };
17
-
18
- validate.projectId = (input) => {
19
- if (input.trim() !== '' && !hasWhitespace(input)) return true;
20
- return 'Project ID must not be empty or contain spaces';
21
- };
22
-
23
- validate.hostname = (input) => {
24
- if (input.split('.').at(-1) === 'com' && !hasWhitespace(input)) return true;
25
- return 'Hostname must not include path to the page to run the check against or spaces';
26
- };
27
-
28
- validate.systemName = (input) => {
29
- if (input.length === 3 && !hasWhitespace(input)) return true;
30
- return 'System name must be 3 characters';
31
- };
32
-
33
- validate.confluenceUrl = (input) => {
34
- if (input === '' || (isUrl(input) && !hasWhitespace(input))) return true;
35
- return 'You must enter a valid URL';
36
- };
37
-
38
- validate.instanceID = (input) => {
39
- if (input.split('/').length === 6 && !hasWhitespace(input)) return true;
40
- return 'You must enter the full instance path (example: projects/example/locations/europe-west1/instances/instanceID)';
41
- };
42
-
43
- validate.databaseId = (input) => {
44
- if (input.split(':').length === 2 && !hasWhitespace(input)) return true;
45
- return 'You must enter the full database path (example: my-project:databaseID)';
46
- };
47
-
48
- validate.pubSubSubscription = (input) => {
49
- if (input.split('/').length === 4 && !hasWhitespace(input)) return true;
50
- return 'You must enter the full subscription path (example: projects/example/subscriptions/subscriptionId)';
51
- };
52
-
53
- validate.path = (input) => {
54
- if (input.includes('/') && !hasWhitespace(input)) return true;
55
- return 'Path must contain a slash and not include spaces';
56
- };
57
-
58
- module.exports = validate;
@@ -1,120 +0,0 @@
1
- const yaml = require('js-yaml');
2
- const fs = require('fs');
3
-
4
- const addDLQ = async (yamlArray, env, dlqTopic) => {
5
- if (env === 'prod') {
6
- /* eslint-disable */
7
- yamlArray[0].dead_letter_topic = dlqTopic;
8
- /* eslint-enable */
9
- }
10
- };
11
-
12
- const appendNotIncludePull = async (inputs, subscriptionFilePath, dlqTopic) => {
13
- const pullArray = [];
14
-
15
- pullArray.push(
16
- {
17
- name: `${inputs.existingTopic}+${inputs.subscriberName}`,
18
- ack_deadline_seconds: '60',
19
- expiration_policy: '',
20
- },
21
- );
22
-
23
- await addDLQ(pullArray, inputs.env, dlqTopic);
24
- const yamlPullArray = yaml.dump(pullArray);
25
- fs.appendFileSync(subscriptionFilePath, `pull_subscriptions:\n${yamlPullArray}`);
26
- };
27
-
28
- const appendIncludePull = async (
29
- fileContent,
30
- originalContentYaml,
31
- subscriptionFilePath,
32
- input,
33
- dlqTopic) => {
34
- if (fileContent.includes('pull_subscriptions')) {
35
- const pullArray = Object.values(originalContentYaml.pull_subscriptions);
36
- const yamlPullArray = yaml.dump(pullArray);
37
- fs.writeFileSync(subscriptionFilePath, `pull_subscriptions:\n${yamlPullArray}`);
38
- }
39
-
40
- const newPullArray = [];
41
-
42
- newPullArray.push(
43
- {
44
- name: `${input.existingTopic}+${input.subscriberName}`,
45
- ack_deadline_seconds: '60',
46
- expiration_policy: '',
47
- },
48
- );
49
-
50
- await addDLQ(newPullArray, input.env, dlqTopic);
51
- const finalYamlPullArray = yaml.dump(newPullArray);
52
- fs.appendFileSync(subscriptionFilePath, finalYamlPullArray);
53
-
54
- if (fileContent.includes('push_subscriptions')) {
55
- const pushArray = Object.values(originalContentYaml.push_subscriptions);
56
- const yamlPushArray = yaml.dump(pushArray);
57
- fs.appendFileSync(subscriptionFilePath, `push_subscriptions:\n${yamlPushArray}`);
58
- }
59
- };
60
-
61
- const appendNotIncludePush = async (inputs, subscriptionFilePath, dlqTopic) => {
62
- const pushArray = [];
63
-
64
- pushArray.push(
65
- {
66
- name: `${inputs.existingTopic}+${inputs.subscriberName}`,
67
- push_endpoint: inputs.pushEndpoint,
68
- oidc_service_account_email: inputs.oidcEmail,
69
- audience: inputs.audience,
70
- expiration_policy: '',
71
- filter: `attributes.Consumer = "${inputs.subscriberName}" OR NOT attributes:Consumer`,
72
- },
73
- );
74
-
75
- await addDLQ(pushArray, inputs.env, dlqTopic);
76
- const yamlPushArray = yaml.dump(pushArray);
77
- fs.appendFileSync(subscriptionFilePath, `push_subscriptions:\n${yamlPushArray}`);
78
- };
79
-
80
- const appendIncludePush = async (
81
- fileContent,
82
- originalContentYaml,
83
- subscriptionFilePath,
84
- input,
85
- dlqTopic) => {
86
- if (fileContent.includes('push_subscriptions')) {
87
- const pushArray = Object.values(originalContentYaml.push_subscriptions);
88
- const yamlPushArray = yaml.dump(pushArray);
89
- fs.writeFileSync(subscriptionFilePath, `push_subscriptions:\n${yamlPushArray}`);
90
- }
91
-
92
- const newPushArray = [];
93
-
94
- newPushArray.push(
95
- {
96
- name: `${input.existingTopic}+${input.subscriberName}`,
97
- push_endpoint: input.pushEndpoint,
98
- oidc_service_account_email: input.oidcEmail,
99
- audience: input.audience,
100
- expiration_policy: '',
101
- filter: `attributes.Consumer = "${input.subscriberName}" OR NOT attributes:Consumer`,
102
- },
103
- );
104
- await addDLQ(newPushArray, input.env, dlqTopic);
105
- const yamlPushArray = yaml.dump(newPushArray);
106
- fs.appendFileSync(subscriptionFilePath, yamlPushArray);
107
-
108
- if (fileContent.includes('pull_subscriptions')) {
109
- const pullArray = Object.values(originalContentYaml.pull_subscriptions);
110
- const yamlPullArray = yaml.dump(pullArray);
111
- fs.appendFileSync(subscriptionFilePath, `pull_subscriptions:\n${yamlPullArray}`);
112
- }
113
- };
114
-
115
- module.exports = {
116
- appendNotIncludePull,
117
- appendIncludePull,
118
- appendNotIncludePush,
119
- appendIncludePush,
120
- };
@@ -1,4 +0,0 @@
1
- {
2
- "name": "Pub/Sub",
3
- "description": "Create a PubSub resource"
4
- }
@@ -1,34 +0,0 @@
1
- const path = require('path');
2
- const fs = require('fs');
3
-
4
- const getKeyValue = (content, key) => {
5
- let value = '';
6
- content.split(/\r?\n/).forEach((line) => {
7
- if (line.startsWith(key)) {
8
- value = line.split('=')[1].replace('"', '').replace('"', '').trim();
9
- }
10
- });
11
- return value;
12
- };
13
-
14
- const getProjectId = (env) => {
15
- let projectId = '';
16
- const projectHCL = path.join('infra', env, 'project.hcl');
17
- if (fs.existsSync(projectHCL)) {
18
- const projectHCLContent = fs.readFileSync(projectHCL, 'utf8');
19
- projectId = getKeyValue(projectHCLContent, ' project_id');
20
- }
21
-
22
- return projectId;
23
- };
24
-
25
- const getProdPushEndopint = (pushEndpoint) => {
26
- let prodPushEndopint = '';
27
- prodPushEndopint = pushEndpoint.replace('.dev', '.com');
28
- return prodPushEndopint;
29
- };
30
-
31
- module.exports = {
32
- getProjectId,
33
- getProdPushEndopint,
34
- };
@@ -1,63 +0,0 @@
1
- const fs = require('fs');
2
- const yaml = require('js-yaml');
3
- const {
4
- appendNotIncludePull, appendIncludePull, appendNotIncludePush, appendIncludePush,
5
- } = require('./append');
6
-
7
- const handleSubscribers = async (
8
- env,
9
- answers,
10
- oidcEmail,
11
- pushEndpoint,
12
- subscriptionFilePath,
13
- dlqTopic) => {
14
- const {
15
- subscriberName,
16
- existingTopic,
17
- pushOrPull,
18
- audience,
19
- } = answers;
20
-
21
- const subscriptionFileContent = fs.readFileSync(subscriptionFilePath, 'utf8');
22
-
23
- const inputs = {
24
- ...this.answers,
25
- env,
26
- existingTopic,
27
- subscriberName,
28
- audience,
29
- oidcEmail,
30
- pushEndpoint,
31
- dlqTopic,
32
- };
33
-
34
- if (pushOrPull === 'pull') {
35
- if (subscriptionFileContent.length === 0 || !subscriptionFileContent.includes('pull_subscriptions')) {
36
- await appendNotIncludePull(inputs, subscriptionFilePath, dlqTopic);
37
- } else {
38
- const originalContentYaml = yaml.load(subscriptionFileContent);
39
- const fileContent = subscriptionFileContent;
40
- await appendIncludePull(
41
- fileContent,
42
- originalContentYaml,
43
- subscriptionFilePath,
44
- inputs,
45
- dlqTopic,
46
- );
47
- }
48
- } else if (subscriptionFileContent.length === 0 || !subscriptionFileContent.includes('push_subscriptions')) {
49
- await appendNotIncludePush(inputs, subscriptionFilePath, dlqTopic);
50
- } else {
51
- const originalContentYaml = yaml.load(subscriptionFileContent);
52
- const fileContent = subscriptionFileContent;
53
- await appendIncludePush(
54
- fileContent,
55
- originalContentYaml,
56
- subscriptionFilePath,
57
- inputs,
58
- dlqTopic,
59
- );
60
- }
61
- };
62
-
63
- module.exports = handleSubscribers;
@@ -1,316 +0,0 @@
1
- const path = require('path');
2
- const chalk = require('chalk');
3
- const fs = require('fs');
4
- const BaseGenerator = require('../../../src/BaseGenerator');
5
- const { required } = require('../../../src/validators');
6
- const {
7
- validSystemName,
8
- validVersion,
9
- validSubscriberName,
10
- checkExistingTopicPath,
11
- } = require('./validate');
12
- const handleSubscribers = require('./handle-subscribers');
13
- const { getProjectId, getProdPushEndopint } = require('./get-gcp-projects');
14
-
15
- module.exports = class extends BaseGenerator {
16
- prompting() {
17
- const prompts = [
18
- {
19
- type: 'list',
20
- name: 'createResource',
21
- message: 'Do you want to create a new topic or a subscription?',
22
- default: 'subscription',
23
- choices: ['topic', 'subscription'],
24
- },
25
- {
26
- when: (response) => response.createResource === 'topic',
27
- type: 'input',
28
- name: 'systemName',
29
- message: 'Please provide three-letter system name as defined in Styra',
30
- validate: (input) => required(input) && validSystemName(input),
31
- },
32
- {
33
- when: (response) => response.createResource === 'topic',
34
- type: 'list',
35
- name: 'scope',
36
- message: 'Please select the scope for the topic',
37
- default: 'private',
38
- choices: ['private', 'public'],
39
- },
40
- {
41
- when: (response) => response.createResource === 'topic',
42
- type: 'list',
43
- name: 'intention',
44
- message: 'Please select the intention of the topic',
45
- default: 'input',
46
- choices: ['input', 'output', 'event', 'notification', 'audit', 'logging'],
47
- },
48
- {
49
- when: (response) => response.createResource === 'topic',
50
- type: 'input',
51
- name: 'payload',
52
- message: 'Please provide the payload (plural for entities, events - verb in the past tense)',
53
- validate: required,
54
- },
55
- {
56
- when: (response) => response.createResource === 'topic',
57
- type: 'input',
58
- name: 'version',
59
- message: 'Please provide the version',
60
- default: 'v1',
61
- validate: (input) => required(input) && validVersion(input),
62
- },
63
- {
64
- when: (response) => response.createResource === 'subscription',
65
- type: 'list',
66
- name: 'externalSub',
67
- message: 'Do you want to create an external subscription?',
68
- default: 'no',
69
- choices: ['no', 'yes'],
70
- validate: required,
71
- },
72
- {
73
- when: (response) => response.createResource === 'subscription' && response.externalSub === 'yes',
74
- type: 'input',
75
- name: 'clanName',
76
- message: 'Please provide the name of your clan',
77
- validate: required,
78
- },
79
- {
80
- when: (response) => response.createResource === 'subscription' && response.externalSub === 'yes',
81
- type: 'input',
82
- name: 'stagingProjectIdConsumer',
83
- message: 'Please provide STAGING project_id of your clan',
84
- validate: required,
85
- },
86
- {
87
- when: (response) => response.createResource === 'subscription' && response.externalSub === 'yes',
88
- type: 'input',
89
- name: 'prodProjectIdConsumer',
90
- message: 'Please provide PRODUCTION project_id of your clan',
91
- validate: required,
92
- },
93
- {
94
- when: (response) => response.createResource === 'subscription' && response.externalSub === 'yes',
95
- type: 'input',
96
- name: 'costCenter',
97
- message: 'Please provide the cost center of your project (specified in your common.hcl file)',
98
- validate: required,
99
- },
100
- {
101
- when: (response) => response.createResource === 'subscription',
102
- type: 'list',
103
- name: 'pushOrPull',
104
- message: 'Please select what type of subscription you want to create',
105
- default: 'push',
106
- choices: ['push', 'pull'],
107
- validate: required,
108
- },
109
- {
110
- when: (response) => response.createResource === 'subscription',
111
- type: 'input',
112
- name: 'subscriberName',
113
- message: 'Please provide the subscriber name in format <system-name>.<service-name>',
114
- validate: (input) => required(input) && validSubscriberName(input),
115
- },
116
- {
117
- when: (response) => response.createResource === 'subscription',
118
- type: 'input',
119
- name: 'existingTopic',
120
- message: 'Please provide the name of the existing topic you want to subscribe to',
121
- validate: (input) => required(input) && checkExistingTopicPath(input),
122
- },
123
- {
124
- when: (response) => response.createResource === 'subscription' && response.pushOrPull === 'push',
125
- type: 'input',
126
- name: 'stagePushEndpoint',
127
- message: 'Please provide the push endpoint for the STAGING environment',
128
- validate: required,
129
- },
130
- {
131
- when: (response) => response.createResource === 'subscription' && response.pushOrPull === 'push',
132
- type: 'input',
133
- name: 'oidcName',
134
- message: 'Please provide the service account name for generating the OIDC token (part after @ will be added automatically)',
135
- validate: required,
136
- },
137
- {
138
- when: (response) => response.createResource === 'subscription' && response.pushOrPull === 'push',
139
- type: 'input',
140
- name: 'audience',
141
- message: 'Please provide the audience that will be used when generating OIDC token',
142
- validate: required,
143
- },
144
- ];
145
-
146
- return this.prompt(prompts).then((props) => {
147
- this.answers = props;
148
- });
149
- }
150
-
151
- writing() {
152
- const {
153
- systemName,
154
- scope,
155
- intention,
156
- payload,
157
- version,
158
- topicName = `${systemName}.${scope}.${intention}.${payload}.${version}`,
159
- subscriberName,
160
- createResource,
161
- existingTopic,
162
- audience,
163
- stagePushEndpoint,
164
- oidcName,
165
- pushOrPull,
166
- clanName,
167
- stagingProjectIdConsumer,
168
- prodProjectIdConsumer,
169
- costCenter,
170
- externalSub,
171
- } = this.answers;
172
-
173
- const dlqTopicName = `dlq.${getProjectId('prod').split('-prod')[0]}.common`;
174
- let dlqTopic = `projects/${getProjectId('prod')}/topics/${dlqTopicName}`;
175
-
176
- const dlqTopicDirPath = path.join(process.cwd(), 'infra', 'prod', 'pubsub', dlqTopicName);
177
- this.fs.copyTpl(
178
- this.templatePath('pubsub-dlq/terragrunt.hcl'),
179
- this.destinationPath(`${dlqTopicDirPath}/terragrunt.hcl`),
180
- {
181
- ...this.answers,
182
- },
183
- );
184
-
185
- ['prod', 'staging'].forEach(async (env) => {
186
- if (createResource === 'topic') {
187
- const topicDirPath = path.join(process.cwd(), 'infra', env, 'pubsub', topicName);
188
- ['terragrunt.hcl', 'spec.hcl'].forEach(async (file) => {
189
- this.fs.copyTpl(
190
- this.templatePath(`pubsub/${file}`),
191
- this.destinationPath(`${topicDirPath}/${file}`),
192
- {
193
- ...this.answers,
194
- env,
195
- topicName,
196
- subscriberName,
197
- dlqTopic,
198
- },
199
- );
200
- });
201
- }
202
-
203
- let projectId = getProjectId(env);
204
- let oidcEmail = `${oidcName}@${projectId}.iam.gserviceaccount.com`;
205
- let pushEndpoint = '';
206
- if (env === 'prod' && pushOrPull === 'push') {
207
- pushEndpoint = getProdPushEndopint(stagePushEndpoint);
208
- } if (env === 'staging' && pushOrPull === 'push') {
209
- pushEndpoint = stagePushEndpoint;
210
- }
211
-
212
- if (createResource === 'subscription' && externalSub === 'no') {
213
- const subscriptionDirPath = path.join(process.cwd(), 'infra', env, 'pubsub', existingTopic);
214
- const fullPath = `${subscriptionDirPath}/subscribers.yaml`;
215
- if (!fs.existsSync(fullPath)) {
216
- fs.writeFileSync(fullPath, '');
217
- this.fs.copyTpl(
218
- this.templatePath('pubsub/subscribers.yaml'),
219
- this.destinationPath(fullPath),
220
- {
221
- ...this.answers,
222
- env,
223
- existingTopic,
224
- subscriberName,
225
- audience,
226
- oidcEmail,
227
- pushEndpoint,
228
- dlqTopic,
229
- },
230
- );
231
- }
232
-
233
- ['terragrunt.hcl', 'spec.hcl'].forEach(async (file) => {
234
- this.fs.copyTpl(
235
- this.templatePath(`pubsub/${file}`),
236
- this.destinationPath(`${subscriptionDirPath}/${file}`),
237
- {
238
- ...this.answers,
239
- env,
240
- existingTopic,
241
- },
242
- );
243
- });
244
-
245
- await handleSubscribers(env, this.answers, oidcEmail, pushEndpoint, `${subscriptionDirPath}/subscribers.yaml`, dlqTopic);
246
- }
247
- if (createResource === 'subscription' && externalSub === 'yes') {
248
- const externalDirPath = path.join(process.cwd(), 'infra', 'prod', 'pubsub', existingTopic, `${clanName}-${env}`);
249
- projectId = getProjectId('prod');
250
- if (!fs.existsSync(externalDirPath)) {
251
- fs.mkdirSync(externalDirPath);
252
- }
253
-
254
- ['terragrunt.hcl', 'spec.hcl'].forEach(async (file) => {
255
- this.fs.copyTpl(
256
- this.templatePath(`pubsub-external/${file}`),
257
- this.destinationPath(`${externalDirPath}/${file}`),
258
- {
259
- ...this.answers,
260
- env,
261
- existingTopic,
262
- stagingProjectIdConsumer,
263
- prodProjectIdConsumer,
264
- costCenter,
265
- subscriberName,
266
- projectId,
267
- },
268
- );
269
- });
270
-
271
- const externalSubPath = `${externalDirPath}/subscribers.yaml`;
272
- if (env === 'staging') {
273
- oidcEmail = `${oidcName}@${stagingProjectIdConsumer}.iam.gserviceaccount.com`;
274
- } else {
275
- oidcEmail = `${oidcName}@${prodProjectIdConsumer}.iam.gserviceaccount.com`;
276
- dlqTopic = `projects/${prodProjectIdConsumer}/topics/${prodProjectIdConsumer.split('-')[0]}-common-dlq`;
277
- }
278
- if (!fs.existsSync(externalSubPath)) {
279
- fs.writeFileSync(externalSubPath, '');
280
- this.fs.copyTpl(
281
- this.templatePath('pubsub-external/subscribers.yaml'),
282
- this.destinationPath(externalSubPath),
283
- {
284
- ...this.answers,
285
- env,
286
- existingTopic,
287
- subscriberName,
288
- audience,
289
- oidcEmail,
290
- pushEndpoint,
291
- dlqTopic,
292
- },
293
- );
294
- }
295
-
296
- await handleSubscribers(
297
- env,
298
- this.answers,
299
- oidcEmail,
300
- pushEndpoint,
301
- externalSubPath,
302
- dlqTopic,
303
- );
304
- }
305
- });
306
- }
307
-
308
- end() {
309
- this.log(`
310
- ${chalk.green(`Your PubSub resources have now been created. To finalize your configuration, please continue
311
- with manual editing of the generated files.`)}
312
- ${chalk.green('1.')} Review created subscribers.
313
- ${chalk.green('2.')} Push this change in a feature branch and open a pull request.
314
- `);
315
- }
316
- };
@@ -1,7 +0,0 @@
1
- locals {<% if (createResource == 'topic') { %>
2
- topic = "<%-topicName%>"
3
- create_subscriptions = false<% } else { %>
4
- topic = "<%-existingTopic%>"
5
- create_subscriptions = true <% } %>
6
- create_topic = true
7
- }