Skip to content

Commit f991c22

Browse files
authored
feat:db master and replica update solution for mysql
1 parent ff37244 commit f991c22

File tree

4 files changed

+9
-1
lines changed

4 files changed

+9
-1
lines changed

examples/mysql-ha/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ module "mysql" {
8080

8181
// Read replica configurations
8282
read_replica_name_suffix = "-test"
83+
replica_database_version = "MYSQL_5_7"
8384
read_replicas = [
8485
{
8586
name = "0"

modules/mysql/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Note: CloudSQL provides [disk autoresize](https://cloud.google.com/sql/docs/mysq
4040
| read\_replica\_name\_suffix | The optional suffix to add to the read instance name | `string` | `""` | no |
4141
| read\_replicas | List of read replicas to create. Encryption key is required for replica in different region. For replica in same region as master set encryption\_key\_name = null | <pre>list(object({<br> name = string<br> tier = string<br> zone = string<br> availability_type = string<br> disk_type = string<br> disk_autoresize = bool<br> disk_autoresize_limit = number<br> disk_size = string<br> user_labels = map(string)<br> database_flags = list(object({<br> name = string<br> value = string<br> }))<br> ip_configuration = object({<br> authorized_networks = list(map(string))<br> ipv4_enabled = bool<br> private_network = string<br> require_ssl = bool<br> allocated_ip_range = string<br> })<br> encryption_key_name = string<br> }))</pre> | `[]` | no |
4242
| region | The region of the Cloud SQL resources | `string` | `"us-central1"` | no |
43+
| replica\_database\_version | The read replica database version to use. This var should only be used during a database update. The update sequence 1. read-replica 2. master, setting this to an updated version will cause the replica to update, then you may update the master with the var database\_version and remove this field after update is complete | `string` | `""` | no |
4344
| secondary\_zone | The preferred zone for the secondary/failover instance, it should be something like: `us-central1-a`, `us-east1-c`. | `string` | `null` | no |
4445
| tier | The tier for the master instance. | `string` | `"db-n1-standard-1"` | no |
4546
| update\_timeout | The optional timout that is applied to limit long database updates. | `string` | `"10m"` | no |

modules/mysql/read_replica.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ resource "google_sql_database_instance" "replicas" {
2525
for_each = local.replicas
2626
project = var.project_id
2727
name = "${local.master_instance_name}-replica${var.read_replica_name_suffix}${each.value.name}"
28-
database_version = var.database_version
28+
database_version = var.replica_database_version != "" ? var.replica_database_version : var.database_version
2929
region = join("-", slice(split("-", lookup(each.value, "zone", var.zone)), 0, 2))
3030
master_instance_name = google_sql_database_instance.default.name
3131
deletion_protection = var.read_replica_deletion_protection

modules/mysql/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ variable "random_instance_name" {
3030
default = false
3131
}
3232

33+
variable "replica_database_version" {
34+
description = "The read replica database version to use. This var should only be used during a database update. The update sequence 1. read-replica 2. master, setting this to an updated version will cause the replica to update, then you may update the master with the var database_version and remove this field after update is complete"
35+
type = string
36+
default = ""
37+
}
38+
3339
// required
3440
variable "database_version" {
3541
description = "The database version to use"

0 commit comments

Comments
 (0)