Skip to content

Commit

Permalink
Merge pull request #1 from recurly/more_flexible_replica_names
Browse files Browse the repository at this point in the history
Allow more control over replica names
  • Loading branch information
konstantin-recurly authored Sep 11, 2020
2 parents c8ae88a + a6738a4 commit 338c044
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
4 changes: 4 additions & 0 deletions RECURLY_CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## [v4.1.0_recurly] - 2020-09-11

- Allow more control over replica names
- Allow setting a replica as a failover target
6 changes: 3 additions & 3 deletions modules/mysql/read_replica.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@

locals {
replicas = {
for x in var.read_replicas : "${var.name}-replica${var.read_replica_name_suffix}${x.name}" => x
for x in var.read_replicas : "${x.name}${var.read_replica_name_suffix}" => x
}
}

resource "google_sql_database_instance" "replicas" {
for_each = local.replicas
project = var.project_id
name = "${local.master_instance_name}-replica${var.read_replica_name_suffix}${each.value.name}"
name = "${each.value.name}${var.read_replica_name_suffix}"
database_version = var.database_version
region = join("-", slice(split("-", lookup(each.value, "zone", var.zone)), 0, 2))
master_instance_name = google_sql_database_instance.default.name

replica_configuration {
failover_target = false
failover_target = lookup(each.value, "failover_target", var.failover_target)
}

settings {
Expand Down
7 changes: 7 additions & 0 deletions modules/mysql/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ variable "random_instance_name" {
default = false
}

variable "failover_target" {
type = bool
description = "Sets random suffix at the end of the Cloud SQL resource name"
default = false
}

// required
variable "database_version" {
description = "The database version to use"
Expand Down Expand Up @@ -172,6 +178,7 @@ variable "read_replicas" {
zone = string
disk_type = string
disk_autoresize = bool
failover_target = bool
disk_size = string
user_labels = map(string)
database_flags = list(object({
Expand Down

0 comments on commit 338c044

Please sign in to comment.