From da47b6fc8e651cb86e3ce6b4c283860d9b8087e7 Mon Sep 17 00:00:00 2001 From: Chico Venancio Date: Wed, 21 Dec 2022 15:19:31 -0300 Subject: [PATCH 1/2] feat(mysql,postgresql): make maintenance window optional --- modules/mysql/README.md | 1 + modules/mysql/main.tf | 11 +++++++---- modules/mysql/variables.tf | 6 ++++++ modules/postgresql/README.md | 1 + modules/postgresql/main.tf | 11 +++++++---- modules/postgresql/variables.tf | 6 ++++++ 6 files changed, 28 insertions(+), 8 deletions(-) diff --git a/modules/mysql/README.md b/modules/mysql/README.md index bc4e384e..83785e6e 100644 --- a/modules/mysql/README.md +++ b/modules/mysql/README.md @@ -31,6 +31,7 @@ Note: CloudSQL provides [disk autoresize](https://cloud.google.com/sql/docs/mysq | insights\_config | The insights\_config settings for the database. |
object({
query_string_length = number
record_application_tags = bool
record_client_address = bool
})
| `null` | no | | ip\_configuration | The ip\_configuration settings subblock |
object({
authorized_networks = list(map(string))
ipv4_enabled = bool
private_network = string
require_ssl = bool
allocated_ip_range = string
})
|
{
"allocated_ip_range": null,
"authorized_networks": [],
"ipv4_enabled": true,
"private_network": null,
"require_ssl": null
}
| no | | maintenance\_window\_day | The day of week (1-7) for the master instance maintenance. | `number` | `1` | no | +| maintenance\_window\_enabled | Whether to enable maintenance window setting for the instance. Replicas must have this set to false. | `bool` | `true` | no | | maintenance\_window\_hour | The hour of day (0-23) maintenance window for the master instance maintenance. | `number` | `23` | no | | maintenance\_window\_update\_track | The update track of maintenance window for the master instance maintenance. Can be either `canary` or `stable`. | `string` | `"canary"` | no | | module\_depends\_on | List of modules or resources this module depends on. | `list(any)` | `[]` | no | diff --git a/modules/mysql/main.tf b/modules/mysql/main.tf index 106ab493..1b47217d 100644 --- a/modules/mysql/main.tf +++ b/modules/mysql/main.tf @@ -123,10 +123,13 @@ resource "google_sql_database_instance" "default" { follow_gae_application = var.follow_gae_application } - maintenance_window { - day = var.maintenance_window_day - hour = var.maintenance_window_hour - update_track = var.maintenance_window_update_track + dynamic "maintenance_window" { + for_each = var.maintenance_window_enabled ? ["enabled"] : [] + content { + day = var.maintenance_window_day + hour = var.maintenance_window_hour + update_track = var.maintenance_window_update_track + } } } diff --git a/modules/mysql/variables.tf b/modules/mysql/variables.tf index 7fcbaee8..5c3c2574 100644 --- a/modules/mysql/variables.tf +++ b/modules/mysql/variables.tf @@ -115,6 +115,12 @@ variable "pricing_plan" { default = "PER_USE" } +variable "maintenance_window_enabled" { + description = "Whether to enable maintenance window setting for the instance. Replicas must have this set to false." + type = bool + default = true +} + variable "maintenance_window_day" { description = "The day of week (1-7) for the master instance maintenance." type = number diff --git a/modules/postgresql/README.md b/modules/postgresql/README.md index 657e235d..9f39fe6a 100644 --- a/modules/postgresql/README.md +++ b/modules/postgresql/README.md @@ -33,6 +33,7 @@ Note: CloudSQL provides [disk autoresize](https://cloud.google.com/sql/docs/mysq | insights\_config | The insights\_config settings for the database. |
object({
query_string_length = number
record_application_tags = bool
record_client_address = bool
})
| `null` | no | | ip\_configuration | The ip configuration for the master instances. |
object({
authorized_networks = list(map(string))
ipv4_enabled = bool
private_network = string
require_ssl = bool
allocated_ip_range = string
})
|
{
"allocated_ip_range": null,
"authorized_networks": [],
"ipv4_enabled": true,
"private_network": null,
"require_ssl": null
}
| no | | maintenance\_window\_day | The day of week (1-7) for the master instance maintenance. | `number` | `1` | no | +| maintenance\_window\_enabled | Whether to enable maintenance window setting for the instance. Replicas must have this set to false. | `bool` | `true` | no | | maintenance\_window\_hour | The hour of day (0-23) maintenance window for the master instance maintenance. | `number` | `23` | no | | maintenance\_window\_update\_track | The update track of maintenance window for the master instance maintenance.Can be either `canary` or `stable`. | `string` | `"canary"` | no | | module\_depends\_on | List of modules or resources this module depends on. | `list(any)` | `[]` | no | diff --git a/modules/postgresql/main.tf b/modules/postgresql/main.tf index 73b77e5d..9ebe8a10 100644 --- a/modules/postgresql/main.tf +++ b/modules/postgresql/main.tf @@ -127,10 +127,13 @@ resource "google_sql_database_instance" "default" { follow_gae_application = var.follow_gae_application } - maintenance_window { - day = var.maintenance_window_day - hour = var.maintenance_window_hour - update_track = var.maintenance_window_update_track + dynamic "maintenance_window" { + for_each = var.maintenance_window_enabled ? ["enabled"] : [] + content { + day = var.maintenance_window_day + hour = var.maintenance_window_hour + update_track = var.maintenance_window_update_track + } } } diff --git a/modules/postgresql/variables.tf b/modules/postgresql/variables.tf index 7deb19d5..4af9cbbb 100644 --- a/modules/postgresql/variables.tf +++ b/modules/postgresql/variables.tf @@ -112,6 +112,12 @@ variable "pricing_plan" { default = "PER_USE" } +variable "maintenance_window_enabled" { + description = "Whether to enable maintenance window setting for the instance. Replicas must have this set to false." + type = bool + default = true +} + variable "maintenance_window_day" { description = "The day of week (1-7) for the master instance maintenance." type = number From 4c93935c377b27c3d4763e772633227bb3275bf1 Mon Sep 17 00:00:00 2001 From: Awais Malik Date: Mon, 9 Jan 2023 19:30:55 +0000 Subject: [PATCH 2/2] updated var description --- modules/mysql/variables.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/mysql/variables.tf b/modules/mysql/variables.tf index 5c3c2574..355b6d2c 100644 --- a/modules/mysql/variables.tf +++ b/modules/mysql/variables.tf @@ -116,7 +116,7 @@ variable "pricing_plan" { } variable "maintenance_window_enabled" { - description = "Whether to enable maintenance window setting for the instance. Replicas must have this set to false." + description = "Whether to enable maintenance window setting for the instance. This does not apply to replicas." type = bool default = true }