forked from terraform-google-modules/terraform-google-sql-db
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathread_replica.tf
91 lines (78 loc) · 2.99 KB
/
read_replica.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/**
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
locals {
replicas = {
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 = "${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 = lookup(each.value, "failover_target", var.failover_target)
}
settings {
tier = lookup(each.value, "tier", var.tier)
activation_policy = "ALWAYS"
dynamic "ip_configuration" {
for_each = [lookup(each.value, "ip_configuration", {})]
content {
ipv4_enabled = lookup(ip_configuration.value, "ipv4_enabled", null)
private_network = lookup(ip_configuration.value, "private_network", null)
require_ssl = lookup(ip_configuration.value, "require_ssl", null)
dynamic "authorized_networks" {
for_each = lookup(ip_configuration.value, "authorized_networks", [])
content {
expiration_time = lookup(authorized_networks.value, "expiration_time", null)
name = lookup(authorized_networks.value, "name", null)
value = lookup(authorized_networks.value, "value", null)
}
}
}
}
disk_autoresize = lookup(each.value, "disk_autoresize", var.disk_autoresize)
disk_size = lookup(each.value, "disk_size", var.disk_size)
disk_type = lookup(each.value, "disk_type", var.disk_type)
pricing_plan = "PER_USE"
user_labels = lookup(each.value, "user_labels", var.user_labels)
dynamic "database_flags" {
for_each = lookup(each.value, "database_flags", [])
content {
name = lookup(database_flags.value, "name", null)
value = lookup(database_flags.value, "value", null)
}
}
location_preference {
zone = lookup(each.value, "zone", var.zone)
}
}
depends_on = [google_sql_database_instance.default]
lifecycle {
ignore_changes = [
settings[0].disk_size,
settings[0].maintenance_window,
]
}
timeouts {
create = var.create_timeout
update = var.update_timeout
delete = var.delete_timeout
}
}