@hiiretail/gcp-infra-cli 0.103.1 → 0.104.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.
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "Firestore",
3
- "description": "Create Firestore indexes"
3
+ "description": "Create Firestore database"
4
4
  }
@@ -9,27 +9,78 @@ module.exports = class extends BaseGenerator {
9
9
  const prompts = [
10
10
  {
11
11
  type: 'input',
12
- name: 'serviceName',
12
+ name: 'databaseName',
13
13
  default: getTribeAndClanName().clan,
14
- message: 'Enter your service name or leave blank for common database',
14
+ message: 'Please provide the database name or leave blank for common database.',
15
15
  validate: required,
16
16
  },
17
17
  {
18
+ type: 'list',
19
+ name: 'databaseType',
20
+ message: 'Select the type of database.',
21
+ default: 'FIRESTORE_NATIVE',
22
+ choices: ['FIRESTORE_NATIVE', 'DATASTORE_MODE'],
23
+ },
24
+ {
25
+ type: 'list',
26
+ name: 'databaseConcurrencyMode',
27
+ message: 'Select the database concurrency mode.',
28
+ default: 'OPTIMISTIC',
29
+ choices: ['OPTIMISTIC', 'PESSIMISTIC'],
30
+ },
31
+ {
32
+ type: 'list',
33
+ name: 'databaseBackupEnabled',
34
+ message: 'Enable database backup?',
35
+ default: 'true',
36
+ choices: ['true', 'false'],
37
+ },
38
+ {
39
+ when: (response) => response.databaseBackupEnabled === 'true',
40
+ type: 'list',
41
+ name: 'databaseBackupSchedule',
42
+ message: 'Select the backup schedule.',
43
+ default: 'daily-backup',
44
+ choices: ['daily-backup', 'weekly-backup'],
45
+ },
46
+ {
47
+ when: (response) => response.databaseBackupSchedule === 'weekly-backup',
48
+ type: 'list',
49
+ name: 'databaseBackupWeeklyRecurrence',
50
+ message: 'Please provide the day of the week the backup must be created.',
51
+ default: 'SUNDAY',
52
+ choices: ['MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY', 'SATURDAY', 'SUNDAY'],
53
+ },
54
+ {
55
+ when: (response) => response.databaseBackupEnabled === 'true',
18
56
  type: 'input',
19
- name: 'collectionName',
20
- message: 'Please provide the name of the collection being indexed',
57
+ name: 'databaseBackupRetention',
58
+ default: '259200s',
59
+ message: 'Please provide how long to keep the backups in seconds. ex. "259200s" is 3 days',
21
60
  validate: required,
22
61
  },
23
62
  {
24
63
  type: 'input',
25
- name: 'fieldPath',
26
- message: 'Please provide the name of the field',
64
+ name: 'databaseCollectionName',
65
+ message: 'Please provide the name of the collection being indexed.',
66
+ validate: required,
67
+ },
68
+ {
69
+ type: 'input',
70
+ name: 'databaseCollectionIndexName',
71
+ message: 'Please provide the name of the index.',
72
+ validate: required,
73
+ },
74
+ {
75
+ type: 'input',
76
+ name: 'databaseCollectionFieldPath',
77
+ message: 'Please provide the name of the field.',
27
78
  validate: required,
28
79
  },
29
80
  {
30
81
  type: 'list',
31
- name: 'order',
32
- message: 'Select the specified order for the field',
82
+ name: 'databaseCollectionFieldorder',
83
+ message: 'Select the specified order for the field.',
33
84
  default: 'ASCENDING',
34
85
  choices: ['ASCENDING', 'DESCENDING'],
35
86
  },
@@ -41,37 +92,46 @@ module.exports = class extends BaseGenerator {
41
92
  }
42
93
 
43
94
  writing() {
44
- const {
45
- serviceName,
46
- collectionName,
47
- fieldPath,
48
- order,
49
- } = this.answers;
95
+ const { databaseName, databaseCollectionName, ...rest } = this.answers;
50
96
 
51
97
  ['prod', 'staging'].forEach((env) => {
52
- this.copyDir(
53
- 'firestore',
54
- path.join('infra', env, 'firestore', serviceName),
55
- {
56
- ...this.answers,
57
- env,
58
- serviceName,
59
- collectionName,
60
- fieldPath,
61
- order,
62
- },
63
- );
98
+ const context = {
99
+ ...rest,
100
+ databaseName,
101
+ databaseCollectionName,
102
+ env,
103
+ };
104
+ const baseDest = path.join('infra', env, 'firestore', databaseName);
105
+ const collectionDest = path.join(baseDest, 'indexes', databaseCollectionName);
106
+
107
+ // Files to copy at database root
108
+ ['spec.hcl', 'terragrunt.hcl'].forEach((file) => {
109
+ this.fs.copyTpl(
110
+ this.templatePath('firestore', file),
111
+ this.destinationPath(baseDest, file),
112
+ context,
113
+ );
114
+ });
115
+
116
+ // Files to copy inside indexes/<databaseCollectionName>/
117
+ ['indexes.yaml', 'terragrunt.hcl'].forEach((file) => {
118
+ this.fs.copyTpl(
119
+ this.templatePath('firestore/indexes', file),
120
+ this.destinationPath(collectionDest, file),
121
+ context,
122
+ );
123
+ });
64
124
  });
65
125
  }
66
126
 
67
127
  end() {
68
128
  const {
69
- serviceName,
129
+ databaseName,
70
130
  } = this.answers;
71
131
 
72
- const firestoreDir = path.join(serviceName);
132
+ const firestoreDir = path.join(databaseName);
73
133
  this.log(`
74
- ${chalk.green(`Your Firestore index has now been created. To finalize your configuration, please continue
134
+ ${chalk.green(`Your Firestore database has now been created. To finalize your configuration, please continue
75
135
  with manual editing of the generated files.`)}
76
136
  ${chalk.green('1.')} Review and add more indexes as the firestore module requires at least two.
77
137
  \u2192 ${chalk.cyan(path.join(firestoreDir, 'indexes.yaml'))}
@@ -3,8 +3,10 @@
3
3
  # it will be added automatically with the same direction as that of the last field defined.
4
4
  # If the final field in a composite index is not directional, the __name__ will be ordered "ASCENDING".
5
5
  indexes:
6
- <%-collectionName%>:
7
- - field_path: "<%-fieldPath%>"
8
- order: "<%-order%>"
6
+ <%-databaseCollectionIndexName%>:
7
+ - field_path: "<%-databaseCollectionFieldPath%>"
8
+ array_config: "CONTAINS"
9
+ order: "<%-databaseCollectionFieldorder%>"
9
10
  - field_path: "__name__"
10
- order: "<%-order%>"
11
+ order: "<%-databaseCollectionFieldorder%>"
12
+ array_config: null
@@ -0,0 +1,27 @@
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-firestore//modules/index?ref=v1.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
+ project_vars = read_terragrunt_config(find_in_parent_folders("project.hcl"))
14
+ collection = basename(get_terragrunt_dir())
15
+ database_name = basename(dirname(dirname(get_terragrunt_dir())))
16
+ }
17
+
18
+ # These are the variables we have to pass in to use the module specified in the terragrunt configuration above
19
+ inputs = merge(
20
+ yamldecode(
21
+ file("${get_terragrunt_dir()}/indexes.yaml")),
22
+ {
23
+ project_id = local.project_vars.locals.project_id
24
+ database_name = local.database_name
25
+ collection = local.collection
26
+ }
27
+ )
@@ -0,0 +1,31 @@
1
+ locals {
2
+ ###################
3
+ # REQUIRED INPUTS #
4
+ ###################
5
+
6
+ database_location_id = "europe-west1"
7
+ database_type = "<%- databaseType %>"
8
+ database_concurrency_mode = "<%- databaseConcurrencyMode %>"
9
+
10
+ ###################
11
+ # OPTIONAL INPUTS #
12
+ ###################
13
+
14
+ # Description: Enables protection of a Firestore database from accidental deletion across all surfaces (API, gcloud, Cloud Console, and Terraform).
15
+ #Type: String
16
+ #Default: "DELETE_PROTECTION_DISABLED"
17
+ database_delete_protection_state = "DELETE_PROTECTION_ENABLED"
18
+
19
+ <% if (databaseBackupEnabled === 'true') { %>
20
+ #Type: Bool
21
+ #Default: true
22
+ # Description: Firestore backup settings
23
+ database_backup_enabled = true
24
+ database_backup_schedule = "<%- databaseBackupSchedule %>"
25
+ <% if (databaseBackupSchedule === 'weekly-backup') { %>
26
+ database_backup_weekly_recurrence = "<%- databaseBackupWeeklyRecurrence %>"
27
+ <% } %>
28
+ database_point_in_time_recovery_enablement = "POINT_IN_TIME_RECOVERY_DISABLED"
29
+ database_backup_retention = "<%- databaseBackupRetention %>"
30
+ <% } %>
31
+ }
@@ -1,7 +1,7 @@
1
1
  # Terragrunt will copy the Terraform configurations specified by the source parameter, along with any files in the
2
2
  # working directory, into a temporary folder, and execute your Terraform commands in that folder.
3
3
  terraform {
4
- source = "git::https://github.com/extenda/tf-module-gcp-firestore//?ref=v0.1.2"
4
+ source = "git::https://github.com/extenda/tf-module-gcp-firestore//modules/database?ref=v1.0.1"
5
5
  }
6
6
 
7
7
  # Include all settings from the root terragrunt.hcl file
@@ -10,16 +10,16 @@ include {
10
10
  }
11
11
 
12
12
  locals {
13
- project_vars = read_terragrunt_config(find_in_parent_folders("project.hcl"))
14
- collection = basename(get_terragrunt_dir())
13
+ project_vars = read_terragrunt_config(find_in_parent_folders("project.hcl"))
14
+ database_name = basename(get_terragrunt_dir())
15
+ database_spec_vars = read_terragrunt_config("${get_terragrunt_dir()}/spec.hcl")
15
16
  }
16
17
 
17
18
  # These are the variables we have to pass in to use the module specified in the terragrunt configuration above
18
19
  inputs = merge(
19
- yamldecode(
20
- file("${get_terragrunt_dir()}/indexes.yaml")),
20
+ local.database_spec_vars.locals,
21
21
  {
22
- project_id = local.project_vars.locals.project_id
23
- collection = local.collection
22
+ project_id = local.project_vars.locals.project_id,
23
+ database_name = local.database_name
24
24
  }
25
25
  )
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hiiretail/gcp-infra-cli",
3
- "version": "0.103.1",
3
+ "version": "0.104.0",
4
4
  "description": "Infrastructure as code generator for GCP.",
5
5
  "main": "src/cli.js",
6
6
  "bin": {