Skip to content

Commit eb300d3

Browse files
authored
feat: Add variable for managing the creation of the default database and user (#163)
1 parent d5e3ec2 commit eb300d3

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

modules/postgresql/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ Note: CloudSQL provides [disk autoresize](https://cloud.google.com/sql/docs/mysq
2323
| disk\_autoresize | Configuration to increase storage size. | bool | `"true"` | no |
2424
| disk\_size | The disk size for the master instance. | string | `"10"` | no |
2525
| disk\_type | The disk type for the master instance. | string | `"PD_SSD"` | no |
26+
| enable\_default\_db | Enable or disable the creation of the default database | bool | `"true"` | no |
27+
| enable\_default\_user | Enable or disable the creation of the default user | bool | `"true"` | no |
2628
| encryption\_key\_name | The full path to the encryption key used for the CMEK disk encryption | string | `"null"` | no |
2729
| ip\_configuration | The ip configuration for the master instances. | object | `<map>` | no |
2830
| maintenance\_window\_day | The day of week (1-7) for the master instance maintenance. | number | `"1"` | no |

modules/postgresql/main.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ resource "google_sql_database_instance" "default" {
117117
}
118118

119119
resource "google_sql_database" "default" {
120+
count = var.enable_default_db ? 1 : 0
120121
name = var.db_name
121122
project = var.project_id
122123
instance = google_sql_database_instance.default.name
@@ -145,6 +146,7 @@ resource "random_id" "user-password" {
145146
}
146147

147148
resource "google_sql_user" "default" {
149+
count = var.enable_default_user ? 1 : 0
148150
name = var.user_name
149151
project = var.project_id
150152
instance = google_sql_database_instance.default.name

modules/postgresql/variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,3 +275,15 @@ variable "read_replica_deletion_protection" {
275275
type = bool
276276
default = false
277277
}
278+
279+
variable "enable_default_db" {
280+
description = "Enable or disable the creation of the default database"
281+
type = bool
282+
default = true
283+
}
284+
285+
variable "enable_default_user" {
286+
description = "Enable or disable the creation of the default user"
287+
type = bool
288+
default = true
289+
}

0 commit comments

Comments
 (0)