Skip to content

Commit 5317931

Browse files
committed
make each ip_configuration pass properly to replicas
Fixes #49
1 parent 227b1ec commit 5317931

File tree

9 files changed

+44
-12
lines changed

9 files changed

+44
-12
lines changed

modules/mysql/failover_replica.tf

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@
1414
* limitations under the License.
1515
*/
1616

17+
locals {
18+
failover_replica_ip_configuration_enabled = "${length(keys(var.failover_replica_ip_configuration)) > 0 ? true : false}"
19+
20+
failover_replica_ip_configurations = {
21+
enabled = "${var.failover_replica_ip_configuration}"
22+
disabled = "${map()}"
23+
}
24+
}
25+
1726
resource "google_sql_database_instance" "failover-replica" {
1827
count = "${var.failover_replica ? 1 : 0}"
1928
project = "${var.project_id}"
@@ -27,7 +36,7 @@ resource "google_sql_database_instance" "failover-replica" {
2736
tier = "${var.failover_replica_tier}"
2837
activation_policy = "${var.failover_replica_activation_policy}"
2938
authorized_gae_applications = ["${var.authorized_gae_applications}"]
30-
ip_configuration = ["${var.failover_replica_ip_configuration}"]
39+
ip_configuration = ["${local.failover_replica_ip_configurations["${local.failover_replica_ip_configuration_enabled ? "enabled" : "disabled"}"]}"]
3140

3241
crash_safe_replication = "${var.failover_replica_crash_safe_replication}"
3342
disk_autoresize = "${var.failover_replica_disk_autoresize}"

modules/mysql/read_replica.tf

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ locals {
2727
mod_by = "${local.zones_enabled ? length(local.read_replica_zones) : 1}"
2828

2929
zones = "${local.zone_mapping["${local.zones_enabled ? "enabled" : "disabled"}"]}"
30+
31+
read_replica_ip_configuration_enabled = "${length(keys(var.read_replica_ip_configuration)) > 0 ? true : false}"
32+
33+
read_replica_ip_configurations = {
34+
enabled = "${var.read_replica_ip_configuration}"
35+
disabled = "${map()}"
36+
}
3037
}
3138

3239
resource "google_sql_database_instance" "replicas" {
@@ -41,7 +48,7 @@ resource "google_sql_database_instance" "replicas" {
4148
settings {
4249
tier = "${var.read_replica_tier}"
4350
activation_policy = "${var.read_replica_activation_policy}"
44-
ip_configuration = ["${local.ip_configurations["${local.ip_configuration_enabled ? "enabled" : "disabled"}"]}"]
51+
ip_configuration = ["${local.read_replica_ip_configurations["${local.read_replica_ip_configuration_enabled ? "enabled" : "disabled"}"]}"]
4552
authorized_gae_applications = ["${var.authorized_gae_applications}"]
4653

4754
crash_safe_replication = "${var.read_replica_crash_safe_replication}"

modules/mysql/variables.tf

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,10 @@ variable "read_replica_user_labels" {
201201

202202
variable "read_replica_ip_configuration" {
203203
description = "The ip configuration for the read replica instances."
204-
default = {}
204+
205+
default = {
206+
ipv4_enabled = "true"
207+
}
205208
}
206209

207210
// Failover replica
@@ -288,7 +291,10 @@ variable "failover_replica_user_labels" {
288291

289292
variable "failover_replica_ip_configuration" {
290293
description = "The ip configuration for the failover replica instances."
291-
default = {}
294+
295+
default = {
296+
ipv4_enabled = "true"
297+
}
292298
}
293299

294300
variable "db_name" {

modules/postgresql/read_replica.tf

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ locals {
2727
mod_by = "${local.zones_enabled ? length(local.read_replica_zones) : 1}"
2828

2929
zones = "${local.zone_mapping["${local.zones_enabled ? "enabled" : "disabled"}"]}"
30+
31+
read_replica_ip_configuration_enabled = "${length(keys(var.read_replica_ip_configuration)) > 0 ? true : false}"
32+
33+
read_replica_ip_configurations = {
34+
enabled = "${var.read_replica_ip_configuration}"
35+
disabled = "${map()}"
36+
}
3037
}
3138

3239
resource "google_sql_database_instance" "replicas" {
@@ -43,7 +50,7 @@ resource "google_sql_database_instance" "replicas" {
4350
activation_policy = "${var.read_replica_activation_policy}"
4451
authorized_gae_applications = ["${var.authorized_gae_applications}"]
4552
availability_type = "${var.read_replica_availability_type}"
46-
ip_configuration = ["${local.ip_configurations["${local.ip_configuration_enabled ? "enabled" : "disabled"}"]}"]
53+
ip_configuration = ["${local.read_replica_ip_configurations["${local.read_replica_ip_configuration_enabled ? "enabled" : "disabled"}"]}"]
4754

4855
crash_safe_replication = "${var.read_replica_crash_safe_replication}"
4956
disk_autoresize = "${var.read_replica_disk_autoresize}"

modules/postgresql/variables.tf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,10 @@ variable "read_replica_replication_type" {
208208

209209
variable "read_replica_ip_configuration" {
210210
description = "The ip configuration for the read instances."
211-
default = {}
211+
212+
default = {
213+
ipv4_enabled = "true"
214+
}
212215
}
213216

214217
variable "db_name" {

test/fixtures/mysql-ha/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ module "mysql" {
8888

8989
read_replica_ip_configuration {
9090
ipv4_enabled = true
91-
require_ssl = true
91+
require_ssl = false
9292

9393
authorized_networks = [{
9494
name = "${var.project}-cidr"
@@ -125,7 +125,7 @@ module "mysql" {
125125

126126
failover_replica_ip_configuration {
127127
ipv4_enabled = true
128-
require_ssl = true
128+
require_ssl = false
129129

130130
authorized_networks = [{
131131
name = "${var.project}-cidr"

test/fixtures/postgresql-ha/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ module "pg" {
9090

9191
read_replica_ip_configuration {
9292
ipv4_enabled = true
93-
require_ssl = true
93+
require_ssl = false
9494

9595
authorized_networks = [{
9696
name = "${var.project}-cidr"

test/integration/mysql-ha/controls/mysql.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
its(:gce_zone) { should eq 'us-central1-a' }
8686

8787
it { expect(settings).to include(expected_settings) }
88-
it { expect(ip_configuration).to include(authorized_networks: [{kind: 'sql#aclEntry', name: "#{project_id}-cidr", value: authorized_network}], ipv4_enabled: true, require_ssl: true) }
88+
it { expect(ip_configuration).to include(authorized_networks: [{kind: 'sql#aclEntry', name: "#{project_id}-cidr", value: authorized_network}], ipv4_enabled: true, require_ssl: false) }
8989
it { expect(database_flags).to include(name: "long_query_time", value: "1") }
9090
it { expect(location_preference).to include(kind: "sql#locationPreference", zone: "us-central1-a") }
9191
it { expect(maintenance_window).to include(kind: "sql#maintenanceWindow", day: 3, hour: 20, update_track: "canary") }
@@ -122,7 +122,7 @@
122122
its(:gce_zone) { should eq "us-central1-#{zone}" }
123123

124124
it { expect(settings).to include(expected_settings) }
125-
it { expect(ip_configuration).to include(authorized_networks: [{kind: 'sql#aclEntry', name: "#{project_id}-cidr", value: authorized_network}], ipv4_enabled: true, require_ssl: true) }
125+
it { expect(ip_configuration).to include(authorized_networks: [{kind: 'sql#aclEntry', name: "#{project_id}-cidr", value: authorized_network}], ipv4_enabled: true, require_ssl: false) }
126126
it { expect(database_flags).to include(name: "long_query_time", value: "1") }
127127
it { expect(location_preference).to include(kind: "sql#locationPreference", zone: "us-central1-#{zone}") }
128128
it { expect(maintenance_window).to include(kind: "sql#maintenanceWindow", day: 1, hour: 22, update_track: "stable") }

test/integration/postgresql-ha/controls/pg.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
its(:gce_zone) { should eq "us-central1-#{zone}" }
8989

9090
it { expect(settings).to include(expected_settings) }
91-
it { expect(ip_configuration).to include(authorized_networks: [{kind: 'sql#aclEntry', name: "#{project_id}-cidr", value: authorized_network}], ipv4_enabled: true, require_ssl: true) }
91+
it { expect(ip_configuration).to include(authorized_networks: [{kind: 'sql#aclEntry', name: "#{project_id}-cidr", value: authorized_network}], ipv4_enabled: true, require_ssl: false) }
9292
it { expect(database_flags).to include(name: "autovacuum", value: "off") }
9393
it { expect(location_preference).to include(kind: "sql#locationPreference", zone: "us-central1-#{zone}") }
9494
it { expect(maintenance_window).to include(kind: "sql#maintenanceWindow", day: 1, hour: 22, update_track: "stable") }

0 commit comments

Comments
 (0)