Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postgres support for private_service_access #43

Merged
merged 3 commits into from
Aug 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion modules/postgresql/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ locals {
enabled = "${var.ip_configuration}"
disabled = "${map()}"
}

peering_completed_enabled = "${var.peering_completed != "" ? true : false}"

user_labels_including_tf_dependency = {
enabled = "${merge(map("tf_dependency", var.peering_completed), var.user_labels)}"
disabled = "${var.user_labels}"
}
}

resource "google_sql_database_instance" "default" {
Expand All @@ -41,9 +48,13 @@ resource "google_sql_database_instance" "default" {
disk_size = "${var.disk_size}"
disk_type = "${var.disk_type}"
pricing_plan = "${var.pricing_plan}"
user_labels = "${var.user_labels}"
database_flags = ["${var.database_flags}"]

// Define a label to force a dependency to the creation of the network peering.
// Substitute this with a module dependency once the module is migrated to
// Terraform 0.12
user_labels = "${local.user_labels_including_tf_dependency["${local.peering_completed_enabled ? "enabled" : "disabled"}"]}"

location_preference {
zone = "${var.region}-${var.zone}"
}
Expand Down
5 changes: 5 additions & 0 deletions modules/postgresql/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ output "instance_address" {
description = "The IPv4 addesses assigned for the master instance"
}

output private_address {
value = "${google_sql_database_instance.default.private_ip_address}"
description = "The private IP address assigned for the master instance"
}

output "instance_first_ip_address" {
value = "${google_sql_database_instance.default.first_ip_address}"
description = "The first IPv4 address of the addresses assigned."
Expand Down
5 changes: 5 additions & 0 deletions modules/postgresql/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ variable "zone" {
description = "The zone for the master instance, it should be something like: `a`, `c`."
}

variable "peering_completed" {
description = "Optional. This is used to ensure that resources are created in the proper order when using private IPs and service network peering."
default = ""
}

variable "activation_policy" {
description = "The activation policy for the master instance.Can be either `ALWAYS`, `NEVER` or `ON_DEMAND`."
default = "ALWAYS"
Expand Down