Skip to content

Commit 4ef3042

Browse files
authored
Merge pull request #43 from g5search/postgres-private-networking
Postgres support for private_service_access
2 parents 9c7727a + d9ba622 commit 4ef3042

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

modules/postgresql/main.tf

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ locals {
2121
enabled = "${var.ip_configuration}"
2222
disabled = "${map()}"
2323
}
24+
25+
peering_completed_enabled = "${var.peering_completed != "" ? true : false}"
26+
27+
user_labels_including_tf_dependency = {
28+
enabled = "${merge(map("tf_dependency", var.peering_completed), var.user_labels)}"
29+
disabled = "${var.user_labels}"
30+
}
2431
}
2532

2633
resource "google_sql_database_instance" "default" {
@@ -41,9 +48,13 @@ resource "google_sql_database_instance" "default" {
4148
disk_size = "${var.disk_size}"
4249
disk_type = "${var.disk_type}"
4350
pricing_plan = "${var.pricing_plan}"
44-
user_labels = "${var.user_labels}"
4551
database_flags = ["${var.database_flags}"]
4652

53+
// Define a label to force a dependency to the creation of the network peering.
54+
// Substitute this with a module dependency once the module is migrated to
55+
// Terraform 0.12
56+
user_labels = "${local.user_labels_including_tf_dependency["${local.peering_completed_enabled ? "enabled" : "disabled"}"]}"
57+
4758
location_preference {
4859
zone = "${var.region}-${var.zone}"
4960
}

modules/postgresql/outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ output "instance_address" {
2525
description = "The IPv4 addesses assigned for the master instance"
2626
}
2727

28+
output private_address {
29+
value = "${google_sql_database_instance.default.private_ip_address}"
30+
description = "The private IP address assigned for the master instance"
31+
}
32+
2833
output "instance_first_ip_address" {
2934
value = "${google_sql_database_instance.default.first_ip_address}"
3035
description = "The first IPv4 address of the addresses assigned."

modules/postgresql/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ variable "zone" {
4242
description = "The zone for the master instance, it should be something like: `a`, `c`."
4343
}
4444

45+
variable "peering_completed" {
46+
description = "Optional. This is used to ensure that resources are created in the proper order when using private IPs and service network peering."
47+
default = ""
48+
}
49+
4550
variable "activation_policy" {
4651
description = "The activation policy for the master instance.Can be either `ALWAYS`, `NEVER` or `ON_DEMAND`."
4752
default = "ALWAYS"

0 commit comments

Comments
 (0)