Skip to content

Commit 0e14063

Browse files
committed
feat(postgres): support read pools
1 parent 3b07de8 commit 0e14063

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

modules/postgresql/read_replica.tf

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ resource "google_sql_database_instance" "replicas" {
3737
master_instance_name = google_sql_database_instance.default.name
3838
deletion_protection = var.read_replica_deletion_protection
3939
encryption_key_name = (join("-", slice(split("-", lookup(each.value, "zone", local.zone)), 0, 2))) == var.region ? null : each.value.encryption_key_name
40+
instance_type = lookup(each.value, "node_count", null) != null ? "READ_POOL_INSTANCE" : "READ_REPLICA_INSTANCE"
41+
node_count = lookup(each.value, "node_count", null)
4042

4143
settings {
4244
tier = lookup(each.value, "tier", null) == null ? var.tier : lookup(each.value, "tier", null)
@@ -98,8 +100,11 @@ resource "google_sql_database_instance" "replicas" {
98100
}
99101
}
100102

101-
location_preference {
102-
zone = lookup(each.value, "zone", local.zone)
103+
dynamic "location_preference" {
104+
for_each = lookup(each.value, "node_count", null) == null ? ["read_pool_instance"] : []
105+
content {
106+
zone = lookup(each.value, "zone", local.zone)
107+
}
103108
}
104109

105110
dynamic "data_cache_config" {

modules/postgresql/variables.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ variable "read_replicas" {
374374
})
375375
encryption_key_name = optional(string)
376376
data_cache_enabled = optional(bool)
377+
node_count = optional(number)
377378
}))
378379
default = []
379380
}

0 commit comments

Comments
 (0)