Skip to content

Commit 5765a5f

Browse files
authored
feat: Add variables for managing the creation of the default database and user (mysql) (#170)
1 parent 55f135f commit 5765a5f

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

modules/mysql/README.md

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

modules/mysql/main.tf

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

123123
resource "google_sql_database" "default" {
124+
count = var.enable_default_db ? 1 : 0
124125
name = var.db_name
125126
project = var.project_id
126127
instance = google_sql_database_instance.default.name
@@ -149,6 +150,7 @@ resource "random_id" "user-password" {
149150
}
150151

151152
resource "google_sql_user" "default" {
153+
count = var.enable_default_user ? 1 : 0
152154
name = var.user_name
153155
project = var.project_id
154156
instance = google_sql_database_instance.default.name

modules/mysql/variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,3 +291,15 @@ variable "read_replica_deletion_protection" {
291291
type = bool
292292
default = false
293293
}
294+
295+
variable "enable_default_db" {
296+
description = "Enable or disable the creation of the default database"
297+
type = bool
298+
default = true
299+
}
300+
301+
variable "enable_default_user" {
302+
description = "Enable or disable the creation of the default user"
303+
type = bool
304+
default = true
305+
}

0 commit comments

Comments
 (0)