@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.
- package/README.md +9 -46
- package/bin/gcp-infra +5 -2
- package/package.json +7 -30
- package/src/gcp-infra.js +87 -0
- package/LICENSE +0 -21
- package/generators/clan-resources/clan-project/generator.json +0 -4
- package/generators/clan-resources/clan-project/index.js +0 -135
- package/generators/clan-resources/clan-project/templates/clan-resources/cloud-nat/terragrunt.hcl +0 -52
- package/generators/clan-resources/clan-project/templates/clan-resources/cloud-nat-static-ip/spec.hcl +0 -7
- package/generators/clan-resources/clan-project/templates/clan-resources/cloud-nat-static-ip/terragrunt.hcl +0 -25
- package/generators/clan-resources/clan-project/templates/clan-resources/cloud-router/terragrunt.hcl +0 -34
- package/generators/clan-resources/clan-project/templates/clan-resources/gke/gke-resources/terragrunt.hcl +0 -40
- package/generators/clan-resources/clan-project/templates/clan-resources/gke/spec.hcl +0 -18
- package/generators/clan-resources/clan-project/templates/clan-resources/gke/terragrunt.hcl +0 -52
- package/generators/clan-resources/clan-project/templates/clan-resources/network/firewall-rules/config/main.tf +0 -41
- package/generators/clan-resources/clan-project/templates/clan-resources/network/firewall-rules/config/vars.tf +0 -9
- package/generators/clan-resources/clan-project/templates/clan-resources/network/firewall-rules/terragrunt.hcl +0 -32
- package/generators/clan-resources/clan-project/templates/clan-resources/network/spec.hcl +0 -54
- package/generators/clan-resources/clan-project/templates/clan-resources/network/terragrunt.hcl +0 -29
- package/generators/clan-resources/clan-project/templates/clan-resources/private-vpc-connection/config/main.tf +0 -18
- package/generators/clan-resources/clan-project/templates/clan-resources/private-vpc-connection/config/vars.tf +0 -27
- package/generators/clan-resources/clan-project/templates/clan-resources/private-vpc-connection/terragrunt.hcl +0 -35
- package/generators/clan-resources/clan-project/templates/clan-resources/serverless-vpc-connector/terragrunt.hcl +0 -40
- package/generators/clan-resources/clan-project/templates/clan-resources/terragrunt.hcl +0 -3
- package/generators/clan-resources/command.json +0 -7
- package/generators/common-resources/bigquery/generator.json +0 -4
- package/generators/common-resources/bigquery/index.js +0 -284
- package/generators/common-resources/bigquery/templates/bigquery/spec.hcl +0 -8
- package/generators/common-resources/bigquery/templates/bigquery/terragrunt.hcl +0 -53
- package/generators/common-resources/bigquery/templates/scheduled-queries/terragrunt.hcl +0 -56
- package/generators/common-resources/bigquery/templates/schema/schema.json +0 -14
- package/generators/common-resources/budget/generator.json +0 -4
- package/generators/common-resources/budget/index.js +0 -89
- package/generators/common-resources/budget/templates/budget/terragrunt.hcl +0 -45
- package/generators/common-resources/cloud-armor/generator.json +0 -4
- package/generators/common-resources/cloud-armor/index.js +0 -45
- package/generators/common-resources/cloud-armor/templates/policies.yaml +0 -53
- package/generators/common-resources/cloud-armor/templates/terragrunt.hcl +0 -30
- package/generators/common-resources/cloud-storage/generator.json +0 -4
- package/generators/common-resources/cloud-storage/index.js +0 -156
- package/generators/common-resources/cloud-storage/templates/cloud-storage/storage.yaml +0 -26
- package/generators/common-resources/cloud-storage/templates/cloud-storage/terragrunt.hcl +0 -32
- package/generators/common-resources/cloudsql/generator.json +0 -4
- package/generators/common-resources/cloudsql/index.js +0 -106
- package/generators/common-resources/cloudsql/templates/mssql/instance/spec.hcl +0 -76
- package/generators/common-resources/cloudsql/templates/mssql/instance/terragrunt.hcl +0 -38
- package/generators/common-resources/cloudsql/templates/mssql/instance-secrets/terragrunt.hcl +0 -37
- package/generators/common-resources/cloudsql/templates/mysql/instance/spec.hcl +0 -73
- package/generators/common-resources/cloudsql/templates/mysql/instance/terragrunt.hcl +0 -40
- package/generators/common-resources/cloudsql/templates/mysql/instance-secrets/terragrunt.hcl +0 -38
- package/generators/common-resources/cloudsql/templates/postgres-clan/instance/spec.hcl +0 -102
- package/generators/common-resources/cloudsql/templates/postgres-clan/instance/terragrunt.hcl +0 -36
- package/generators/common-resources/cloudsql/templates/postgres-clan/instance-secrets/terragrunt.hcl +0 -44
- package/generators/common-resources/cloudsql-database/generator.json +0 -4
- package/generators/common-resources/cloudsql-database/index.js +0 -70
- package/generators/common-resources/cloudsql-database/templates/mysql/database/proxy_port.hcl +0 -4
- package/generators/common-resources/cloudsql-database/templates/mysql/database/terragrunt.hcl +0 -69
- package/generators/common-resources/cloudsql-database/templates/mysql/outputs.json +0 -5
- package/generators/common-resources/cloudsql-database/templates/mysql/secrets/terragrunt.hcl +0 -30
- package/generators/common-resources/cloudsql-database/templates/postgres/database/proxy_port.hcl +0 -4
- package/generators/common-resources/cloudsql-database/templates/postgres/database/spec.hcl +0 -17
- package/generators/common-resources/cloudsql-database/templates/postgres/database/terragrunt.hcl +0 -74
- package/generators/common-resources/cloudsql-database/templates/postgres/outputs.json +0 -5
- package/generators/common-resources/cloudsql-database/templates/postgres/secrets/terragrunt.hcl +0 -30
- package/generators/common-resources/command.json +0 -8
- package/generators/common-resources/confluent-cluster/generator.json +0 -4
- package/generators/common-resources/confluent-cluster/index.js +0 -52
- package/generators/common-resources/confluent-cluster/templates/confluent/spec.hcl +0 -5
- package/generators/common-resources/confluent-cluster/templates/confluent/terragrunt.hcl +0 -25
- package/generators/common-resources/datastore/generator.json +0 -4
- package/generators/common-resources/datastore/index.js +0 -91
- package/generators/common-resources/datastore/templates/datastore/indexes.yaml +0 -6
- package/generators/common-resources/datastore/templates/datastore/terragrunt.hcl +0 -23
- package/generators/common-resources/elastic-cloud/generator.json +0 -4
- package/generators/common-resources/elastic-cloud/index.js +0 -52
- package/generators/common-resources/elastic-cloud/templates/elastic/spec.hcl +0 -27
- package/generators/common-resources/elastic-cloud/templates/elastic/terragrunt.hcl +0 -27
- package/generators/common-resources/elastic-index-policy/generator.json +0 -4
- package/generators/common-resources/elastic-index-policy/handle-yaml.js +0 -76
- package/generators/common-resources/elastic-index-policy/index.js +0 -210
- package/generators/common-resources/elastic-index-policy/templates/policy/policy.yaml +0 -28
- package/generators/common-resources/elastic-index-policy/templates/policy/terragrunt.hcl +0 -25
- package/generators/common-resources/elastic-template/generator.json +0 -4
- package/generators/common-resources/elastic-template/index.js +0 -84
- package/generators/common-resources/elastic-template/templates/elastic-template/mappings.json +0 -1
- package/generators/common-resources/elastic-template/templates/elastic-template/terragrunt.hcl +0 -35
- package/generators/common-resources/firestore/generator.json +0 -4
- package/generators/common-resources/firestore/index.js +0 -141
- package/generators/common-resources/firestore/templates/firestore/indexes/indexes.yaml +0 -12
- package/generators/common-resources/firestore/templates/firestore/indexes/terragrunt.hcl +0 -27
- package/generators/common-resources/firestore/templates/firestore/spec.hcl +0 -31
- package/generators/common-resources/firestore/templates/firestore/terragrunt.hcl +0 -25
- package/generators/common-resources/iam/generator.json +0 -4
- package/generators/common-resources/iam/index.js +0 -62
- package/generators/common-resources/iam/templates/github/workflows/iam.yml +0 -18
- package/generators/common-resources/iam/templates/iam.yaml +0 -8
- package/generators/common-resources/iam/valid-prefix.js +0 -8
- package/generators/common-resources/kafka-connect/generator.json +0 -4
- package/generators/common-resources/kafka-connect/index.js +0 -75
- package/generators/common-resources/kafka-connect/templates/elastic/terragrunt.hcl +0 -92
- package/generators/common-resources/kafka-connect/templates/pubsub/terragrunt.hcl +0 -75
- package/generators/common-resources/kafka-topics/generator.json +0 -4
- package/generators/common-resources/kafka-topics/index.js +0 -54
- package/generators/common-resources/kafka-topics/templates/kafka/kafka.yaml +0 -20
- package/generators/common-resources/kafka-topics/templates/kafka/terragrunt.hcl +0 -21
- package/generators/common-resources/kms/generator.json +0 -4
- package/generators/common-resources/kms/index.js +0 -69
- package/generators/common-resources/kms/templates/kms/spec.hcl +0 -5
- package/generators/common-resources/kms/templates/kms/terragrunt.hcl +0 -33
- package/generators/common-resources/memorystore/generator.json +0 -4
- package/generators/common-resources/memorystore/index.js +0 -69
- package/generators/common-resources/memorystore/templates/outputs.json +0 -3
- package/generators/common-resources/memorystore/templates/redis-instance/spec.hcl +0 -16
- package/generators/common-resources/memorystore/templates/redis-instance/terragrunt.hcl +0 -35
- package/generators/common-resources/memorystore/templates/secrets/terragrunt.hcl +0 -31
- package/generators/common-resources/monitoring/generator.json +0 -4
- package/generators/common-resources/monitoring/handle-yaml.js +0 -48
- package/generators/common-resources/monitoring/index.js +0 -192
- package/generators/common-resources/monitoring/templates/alerts/generic-infra.yaml +0 -633
- package/generators/common-resources/monitoring/templates/alerts/terragrunt.hcl +0 -37
- package/generators/common-resources/monitoring/templates/service/service.yaml +0 -16
- package/generators/common-resources/monitoring/templates/service/terragrunt.hcl +0 -37
- package/generators/common-resources/monitoring/templates/uptime-checks/terragrunt.hcl +0 -36
- package/generators/common-resources/monitoring/templates/uptime-checks/uptime-checks.yaml +0 -3
- package/generators/common-resources/monitoring/validate.js +0 -58
- package/generators/common-resources/pubsub/append.js +0 -120
- package/generators/common-resources/pubsub/generator.json +0 -4
- package/generators/common-resources/pubsub/get-gcp-projects.js +0 -34
- package/generators/common-resources/pubsub/handle-subscribers.js +0 -63
- package/generators/common-resources/pubsub/index.js +0 -316
- package/generators/common-resources/pubsub/templates/pubsub/spec.hcl +0 -7
- package/generators/common-resources/pubsub/templates/pubsub/subscribers.yaml +0 -16
- package/generators/common-resources/pubsub/templates/pubsub/terragrunt.hcl +0 -34
- package/generators/common-resources/pubsub/templates/pubsub-dlq/terragrunt.hcl +0 -42
- package/generators/common-resources/pubsub/templates/pubsub-external/spec.hcl +0 -10
- package/generators/common-resources/pubsub/templates/pubsub-external/subscribers.yaml +0 -16
- package/generators/common-resources/pubsub/templates/pubsub-external/terragrunt.hcl +0 -31
- package/generators/common-resources/pubsub/validate.js +0 -44
- package/generators/common-resources/scheduler/append.js +0 -83
- package/generators/common-resources/scheduler/generator.json +0 -4
- package/generators/common-resources/scheduler/index.js +0 -103
- package/generators/common-resources/scheduler/templates/scheduler/terragrunt.hcl +0 -44
- package/generators/common-resources/spanner/append.js +0 -27
- package/generators/common-resources/spanner/generator.json +0 -4
- package/generators/common-resources/spanner/index.js +0 -169
- package/generators/common-resources/spanner/templates/spanner/databases.yaml +0 -5
- package/generators/common-resources/spanner/templates/spanner/spec.hcl +0 -22
- package/generators/common-resources/spanner/templates/spanner/terragrunt.hcl +0 -33
- package/generators/common-resources/spanner/validate.js +0 -38
- package/generators/docs/command.json +0 -7
- package/generators/docs/rca/generator.json +0 -4
- package/generators/docs/rca/index.js +0 -50
- package/generators/docs/rca/templates/docs/rca_external.md +0 -43
- package/generators/docs/rca/templates/docs/rca_internal.md +0 -88
- package/generators/docs/runbook/generator.json +0 -4
- package/generators/docs/runbook/index.js +0 -42
- package/generators/docs/runbook/templates/docs/runbook.md +0 -106
- package/generators/docs/srb/generator.json +0 -4
- package/generators/docs/srb/index.js +0 -62
- package/generators/docs/srb/templates/docs/README.md +0 -42
- package/generators/docs/srb/templates/docs/adr.cmd +0 -3
- package/generators/docs/srb/templates/docs/adr.sh +0 -4
- package/generators/docs/srb/templates/docs/architecture.md +0 -68
- package/generators/docs/srb/templates/docs/cost-estimates.md +0 -39
- package/generators/docs/srb/templates/docs/dsl2png.cmd +0 -3
- package/generators/docs/srb/templates/docs/dsl2png.sh +0 -4
- package/generators/docs/srb/templates/docs/sre.md +0 -43
- package/generators/docs/srb/templates/sample.dsl +0 -36
- package/generators/init/clan-infra/gcp-projects.js +0 -36
- package/generators/init/clan-infra/generator.json +0 -4
- package/generators/init/clan-infra/index.js +0 -170
- package/generators/init/clan-infra/templates/.yamllint +0 -17
- package/generators/init/clan-infra/templates/env/project.hcl +0 -15
- package/generators/init/clan-infra/templates/env/secrets/secrets.yaml +0 -4
- package/generators/init/clan-infra/templates/env/secrets/terragrunt.hcl +0 -31
- package/generators/init/clan-infra/templates/github/CODEOWNERS +0 -1
- package/generators/init/clan-infra/templates/github/workflows/infra-verify.yml +0 -16
- package/generators/init/clan-infra/templates/github/workflows/infra.yml +0 -17
- package/generators/init/clan-infra/templates/github/workflows/release-notes.yml +0 -33
- package/generators/init/clan-infra/templates/github/workflows/sync-docs.yml +0 -29
- package/generators/init/clan-infra/templates/infra/.terraform-version +0 -1
- package/generators/init/clan-infra/templates/infra/.terragrunt-version +0 -1
- package/generators/init/clan-infra/templates/infra/README.md +0 -5
- package/generators/init/clan-infra/templates/infra/common.hcl +0 -24
- package/generators/init/clan-infra/templates/infra/terragrunt_root.hcl +0 -44
- package/generators/init/clan-infra/templates/notification-channels/notification-channels.yaml +0 -7
- package/generators/init/clan-infra/templates/notification-channels/terragrunt.hcl +0 -29
- package/generators/init/clan-infra/templates/release-notes/example-service.yaml +0 -23
- package/generators/init/clan-infra/templates/release-notes-schema/release-notes.schema.json +0 -63
- package/generators/init/clan-infra/tribe-clan-repo.js +0 -38
- package/generators/init/clan-infra/validate.js +0 -8
- package/generators/init/command.json +0 -7
- package/generators/maintenance/command.json +0 -7
- package/generators/maintenance/manage-states/generator.json +0 -4
- package/generators/maintenance/manage-states/index.js +0 -188
- package/generators/maintenance/update-modules/generator.json +0 -4
- package/generators/maintenance/update-modules/index.js +0 -102
- package/generators/organization/clan-project/__tests__/__snapshots__/googlecloud.test.js.snap +0 -27
- package/generators/organization/clan-project/generator.json +0 -4
- package/generators/organization/clan-project/googlecloud.js +0 -119
- package/generators/organization/clan-project/index.js +0 -139
- package/generators/organization/clan-project/templates/clan/clan.yaml +0 -22
- package/generators/organization/clan-project/templates/clan/terragrunt.hcl +0 -39
- package/generators/organization/clan-project/templates/clan-project/project.yaml +0 -14
- package/generators/organization/clan-project/templates/clan-project/terragrunt.hcl +0 -51
- package/generators/organization/clan-project/templates/clans-folder/terragrunt.hcl +0 -3
- package/generators/organization/clan-project/templates/department/terragrunt.hcl +0 -32
- package/generators/organization/clan-project/templates/tribe/terragrunt.hcl +0 -67
- package/generators/organization/clan-project/templates/tribe/tribe.yaml +0 -19
- package/generators/organization/command.json +0 -8
- package/src/BaseGenerator.js +0 -73
- package/src/SecretsGenerator.js +0 -105
- package/src/cli.js +0 -73
- package/src/dependency-check.js +0 -48
- package/src/update-check.js +0 -30
- package/src/validators.js +0 -32
- package/src/yeoman.js +0 -71
|
@@ -1,35 +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/terraform-google-modules/terraform-google-memorystore//?ref=v10.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
|
-
locals {
|
|
13
|
-
spec_vars = read_terragrunt_config("${get_terragrunt_dir()}/spec.hcl")
|
|
14
|
-
project_vars = read_terragrunt_config(find_in_parent_folders("project.hcl"))
|
|
15
|
-
common_vars = read_terragrunt_config(find_in_parent_folders("common.hcl"))
|
|
16
|
-
service_name = basename(get_terragrunt_dir())
|
|
17
|
-
labels = merge(local.common_vars.locals.default_user_labels, local.project_vars.locals.default_user_labels, {
|
|
18
|
-
component = local.common_vars.locals.component
|
|
19
|
-
product = local.common_vars.locals.product
|
|
20
|
-
project = local.project_vars.locals.project_name
|
|
21
|
-
tenant-alias = local.common_vars.locals.tenant_alias
|
|
22
|
-
})
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
# These are the variables we have to pass in to use the module specified in the terragrunt configuration above
|
|
26
|
-
inputs = merge(
|
|
27
|
-
local.spec_vars.locals,
|
|
28
|
-
{
|
|
29
|
-
name = "memorystore-${local.service_name}-${local.project_vars.locals.project_env}-clan"
|
|
30
|
-
project = local.project_vars.locals.project_id
|
|
31
|
-
authorized_network = "projects/${local.project_vars.locals.project_id}/global/networks/${local.project_vars.locals.clan_network}"
|
|
32
|
-
enable_apis = false
|
|
33
|
-
labels = local.labels
|
|
34
|
-
}
|
|
35
|
-
)
|
|
@@ -1,31 +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-secret-manager//?ref=v0.1.2"
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
locals {
|
|
8
|
-
project_vars = read_terragrunt_config(find_in_parent_folders("project.hcl"))
|
|
9
|
-
common_vars = read_terragrunt_config(find_in_parent_folders("common.hcl"))
|
|
10
|
-
labels = merge(local.common_vars.locals.default_user_labels, local.project_vars.locals.default_user_labels, {
|
|
11
|
-
component = local.common_vars.locals.component
|
|
12
|
-
product = local.common_vars.locals.product
|
|
13
|
-
tenant-alias = local.common_vars.locals.tenant_alias
|
|
14
|
-
terraform = ""
|
|
15
|
-
})
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
# Include all settings from the root terragrunt.hcl file
|
|
19
|
-
include {
|
|
20
|
-
path = find_in_parent_folders("terragrunt_root.hcl")
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
<%-dependencies%>
|
|
24
|
-
|
|
25
|
-
# These are the variables we have to pass in to use the module specified in the terragrunt configuration above
|
|
26
|
-
inputs = {
|
|
27
|
-
project_id = local.project_vars.locals.project_id
|
|
28
|
-
secrets = {<%-secrets%>
|
|
29
|
-
}
|
|
30
|
-
labels = local.labels
|
|
31
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
const ejs = require('ejs');
|
|
2
|
-
const _ = require('lodash');
|
|
3
|
-
|
|
4
|
-
function cleanAlerts(alerts) {
|
|
5
|
-
const copy = [...alerts];
|
|
6
|
-
return copy.map((obj) => {
|
|
7
|
-
/* eslint-disable no-param-reassign */
|
|
8
|
-
if (_.get(obj, 'enabled') === true) delete obj.enabled;
|
|
9
|
-
|
|
10
|
-
return obj;
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const handleAlert = (templates, answers) => {
|
|
15
|
-
const alerts = [];
|
|
16
|
-
|
|
17
|
-
Object.entries(templates).forEach(([, template]) => {
|
|
18
|
-
const newAlert = JSON.parse(ejs.render(JSON.stringify(template), answers));
|
|
19
|
-
alerts.push(newAlert);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
const cleanedAlerts = cleanAlerts(alerts);
|
|
23
|
-
|
|
24
|
-
return Array.isArray(cleanedAlerts) ? cleanedAlerts : [cleanedAlerts];
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const handleAlerts = (alerts, templates, answers) => {
|
|
28
|
-
const newAlertsList = [];
|
|
29
|
-
|
|
30
|
-
const newAlerts = handleAlert(templates, answers);
|
|
31
|
-
|
|
32
|
-
newAlertsList.push(...newAlerts);
|
|
33
|
-
return newAlertsList;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const handleUptimeChecks = (slos, templates, answers) => {
|
|
37
|
-
const newUptimeCheck = JSON.parse(ejs.render(JSON.stringify(templates), answers));
|
|
38
|
-
|
|
39
|
-
slos.push(newUptimeCheck);
|
|
40
|
-
return slos;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
module.exports = {
|
|
44
|
-
handleAlert,
|
|
45
|
-
handleAlerts,
|
|
46
|
-
handleUptimeChecks,
|
|
47
|
-
cleanAlerts,
|
|
48
|
-
};
|
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
const chalk = require('chalk');
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
const ejs = require('ejs');
|
|
5
|
-
const yaml = require('js-yaml');
|
|
6
|
-
const BaseGenerator = require('../../../src/BaseGenerator');
|
|
7
|
-
const { required } = require('../../../src/validators');
|
|
8
|
-
const validate = require('./validate');
|
|
9
|
-
const {
|
|
10
|
-
handleAlerts,
|
|
11
|
-
handleUptimeChecks,
|
|
12
|
-
cleanAlerts,
|
|
13
|
-
} = require('./handle-yaml');
|
|
14
|
-
|
|
15
|
-
const uptimeCheckTemplates = yaml.load(fs.readFileSync(`${__dirname}/templates/uptime-checks/uptime-checks.yaml`));
|
|
16
|
-
const alertTemplates = yaml.load(fs.readFileSync(`${__dirname}/templates/alerts/generic-infra.yaml`));
|
|
17
|
-
|
|
18
|
-
/* istanbul ignore next */
|
|
19
|
-
module.exports = class extends BaseGenerator {
|
|
20
|
-
async prompting() {
|
|
21
|
-
this.answers = await this.prompt([
|
|
22
|
-
{
|
|
23
|
-
type: 'list',
|
|
24
|
-
name: 'monitoringResource',
|
|
25
|
-
message: 'Select the resource you want to create:',
|
|
26
|
-
choices: [
|
|
27
|
-
'alerts',
|
|
28
|
-
'uptime-checks',
|
|
29
|
-
],
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
when: (response) => response.monitoringResource === 'alerts',
|
|
33
|
-
type: 'list',
|
|
34
|
-
name: 'alert',
|
|
35
|
-
message: 'Select the category of alerts you want to create:',
|
|
36
|
-
choices: Object.keys(alertTemplates),
|
|
37
|
-
},
|
|
38
|
-
|
|
39
|
-
{
|
|
40
|
-
when: (response) => response.monitoringResource === 'alerts',
|
|
41
|
-
type: 'list',
|
|
42
|
-
name: 'allOrSpecific',
|
|
43
|
-
message: 'Do you want to create a specific alert or all recommended alerts?',
|
|
44
|
-
choices: (response) => [
|
|
45
|
-
`All (${Object.keys(alertTemplates[response.alert] || {}).length})`,
|
|
46
|
-
'Specific',
|
|
47
|
-
],
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
when: (response) => response.monitoringResource === 'alerts' && response.allOrSpecific === 'Specific',
|
|
51
|
-
type: 'list',
|
|
52
|
-
name: 'specificAlert',
|
|
53
|
-
message: (response) => `Select the specific alert you want to create for ${response.alert}:`,
|
|
54
|
-
choices: (response) => Object.keys(alertTemplates[response.alert]),
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
when: (response) => response.monitoringResource === 'alerts',
|
|
58
|
-
type: 'input',
|
|
59
|
-
name: 'clan',
|
|
60
|
-
message: 'Please provide the clan name (ex: SRE, PNP, IAM...):',
|
|
61
|
-
default: () => {
|
|
62
|
-
const gitPath = path.resolve(process.cwd(), '.git');
|
|
63
|
-
if (fs.existsSync(gitPath)) {
|
|
64
|
-
const repoName = path.basename(process.cwd());
|
|
65
|
-
const regex = /-([a-z]{3})-/i;
|
|
66
|
-
const match = regex.exec(repoName);
|
|
67
|
-
return match ? match[1].toUpperCase() : '';
|
|
68
|
-
}
|
|
69
|
-
return '';
|
|
70
|
-
},
|
|
71
|
-
validate: required && validate.clan,
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
when: (response) => response.monitoringResource === 'alerts',
|
|
75
|
-
type: 'input',
|
|
76
|
-
name: 'projectId',
|
|
77
|
-
message: 'Please provide the project ID:',
|
|
78
|
-
validate: required && validate.projectId,
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
when: (response) => response.monitoringResource === 'uptime-checks',
|
|
82
|
-
type: 'input',
|
|
83
|
-
name: 'serviceName',
|
|
84
|
-
message: 'Please provide the namespace where the service resides:',
|
|
85
|
-
default: (response) => `${response.clan}-service`,
|
|
86
|
-
validate: required && validate.serviceName,
|
|
87
|
-
},
|
|
88
|
-
{
|
|
89
|
-
when: (response) => response.monitoringResource === 'uptime-checks',
|
|
90
|
-
type: 'input',
|
|
91
|
-
name: 'hostname',
|
|
92
|
-
message: 'Please provide the base hostname of the service (ex: my-service.retailsvc.com):',
|
|
93
|
-
validate: required && validate.hostname,
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
when: (response) => response.monitoringResource === 'uptime-checks',
|
|
97
|
-
type: 'input',
|
|
98
|
-
name: 'runbookLink',
|
|
99
|
-
message: 'Please provide the full URL to your runbook in confluence (Leave empty if none):',
|
|
100
|
-
validate: required && validate.runbookLink,
|
|
101
|
-
},
|
|
102
|
-
{
|
|
103
|
-
when: (response) => response.monitoringResource === 'uptime-checks',
|
|
104
|
-
type: 'input',
|
|
105
|
-
name: 'path',
|
|
106
|
-
message: 'Please provide the path/endpoint to run the check against (ex: /health):',
|
|
107
|
-
validate: required && validate.path,
|
|
108
|
-
},
|
|
109
|
-
]);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
async writing() {
|
|
113
|
-
const { monitoringResource } = this.answers;
|
|
114
|
-
const resourceDir = path.join(process.cwd(), 'infra', 'prod', 'monitoring', monitoringResource);
|
|
115
|
-
|
|
116
|
-
const copyTemplate = (resource, resourcePath, yamlPath) => {
|
|
117
|
-
if (!fs.existsSync(resourcePath)) fs.mkdirSync(resourcePath, { recursive: true });
|
|
118
|
-
if (!fs.existsSync(yamlPath)) fs.appendFileSync(yamlPath, '');
|
|
119
|
-
if (!fs.existsSync(`${resourcePath}/terragrunt.hcl`)) {
|
|
120
|
-
this.fs.copyTpl(
|
|
121
|
-
this.templatePath(`${resource}/terragrunt.hcl`),
|
|
122
|
-
this.destinationPath(`${resourcePath}/terragrunt.hcl`),
|
|
123
|
-
this.answers,
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
/* istanbul ignore next */
|
|
129
|
-
if (monitoringResource === 'alerts' && this.answers.allOrSpecific === 'Specific') {
|
|
130
|
-
const yamlPath = `${resourceDir}/base-specific.yaml`;
|
|
131
|
-
|
|
132
|
-
copyTemplate('alerts', resourceDir, yamlPath);
|
|
133
|
-
|
|
134
|
-
const oldYaml = yaml.load(fs.readFileSync(yamlPath, 'utf8')) || [];
|
|
135
|
-
const template = alertTemplates[this.answers.alert][this.answers.specificAlert];
|
|
136
|
-
const newAlert = JSON.parse(ejs.render(JSON.stringify(template), this.answers));
|
|
137
|
-
|
|
138
|
-
oldYaml.push(newAlert);
|
|
139
|
-
const cleanedAlerts = cleanAlerts(oldYaml);
|
|
140
|
-
|
|
141
|
-
fs.writeFileSync(
|
|
142
|
-
yamlPath,
|
|
143
|
-
yaml.dump(cleanedAlerts, {
|
|
144
|
-
lineWidth: 250,
|
|
145
|
-
noArrayIndent: false,
|
|
146
|
-
}),
|
|
147
|
-
);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/* istanbul ignore next */
|
|
151
|
-
if (monitoringResource === 'alerts' && this.answers.allOrSpecific === `All (${Object.keys(alertTemplates[this.answers.alert] || {}).length})`) {
|
|
152
|
-
const yamlPath = `${resourceDir}/base.yaml`;
|
|
153
|
-
|
|
154
|
-
copyTemplate('alerts', resourceDir, yamlPath);
|
|
155
|
-
|
|
156
|
-
const oldYaml = yaml.load(fs.readFileSync(yamlPath, 'utf8')) || [];
|
|
157
|
-
const newAlerts = handleAlerts(oldYaml, alertTemplates[this.answers.alert], this.answers);
|
|
158
|
-
const currentContent = fs.readFileSync(yamlPath, 'utf8');
|
|
159
|
-
|
|
160
|
-
if (currentContent !== '') {
|
|
161
|
-
fs.appendFileSync(yamlPath, '\n');
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
newAlerts.forEach((alert, index) => {
|
|
165
|
-
fs.appendFileSync(yamlPath, yaml.dump([alert], { lineWidth: 250, noArrayIndent: false }));
|
|
166
|
-
if (index !== newAlerts.length - 1) {
|
|
167
|
-
fs.appendFileSync(yamlPath, '\n');
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
if (monitoringResource === 'uptime-checks') {
|
|
173
|
-
const yamlPath = `${resourceDir}/uptime-checks.yaml`;
|
|
174
|
-
|
|
175
|
-
copyTemplate('uptime-checks', resourceDir, yamlPath);
|
|
176
|
-
|
|
177
|
-
const oldYaml = yaml.load(fs.readFileSync(yamlPath, 'utf8')) || [];
|
|
178
|
-
const newYaml = await handleUptimeChecks(oldYaml, uptimeCheckTemplates, this.answers);
|
|
179
|
-
|
|
180
|
-
fs.writeFileSync(yamlPath, yaml.dump(newYaml, { lineWidth: 250, noArrayIndent: true }));
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
end() {
|
|
185
|
-
this.log(`
|
|
186
|
-
${chalk.yellow('Your monitoring resources have now been created.')}
|
|
187
|
-
${chalk.green('1.')} Please note that these are just example configurations and might need further adjustments.
|
|
188
|
-
${chalk.green('2.')} To finalize your configuration, please continue with manual editing of the generated files.
|
|
189
|
-
${chalk.green('3.')} Push the changes in a feature branch and open a pull request.
|
|
190
|
-
`);
|
|
191
|
-
}
|
|
192
|
-
};
|