Skip to content

Commit 6956590

Browse files
Merge branch 'master' into je-DDO-4168
2 parents 233b00c + d11bba2 commit 6956590

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

terraform-modules/cloudsql-postgres/cloudsql.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@ resource "google_sql_database_instance" "cloudsql_instance" {
5353
}
5454

5555
ip_configuration {
56-
ipv4_enabled = var.private_enable == true ? false : true
56+
ipv4_enabled = (var.private_enable && !var.private_enable_public_ip) ? false : true
5757
private_network = var.private_enable == true ? local.private_network : null
5858
ssl_mode = "TRUSTED_CLIENT_CERTIFICATE_REQUIRED"
59+
enable_private_path_for_google_cloud_services = var.private_enable ? true : null
5960
dynamic "authorized_networks" {
6061
for_each = var.cloudsql_authorized_networks
6162
content {

terraform-modules/cloudsql-postgres/variables.tf

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,12 @@ variable "private_enable" {
177177
default = false
178178
}
179179

180+
variable "private_enable_public_ip" {
181+
type = bool
182+
description = "If true, enable private AND public IPs for the CloudSQL instance"
183+
default = false
184+
}
185+
180186
variable "enable_private_services" {
181187
type = bool
182188
description = "Enable flag for a private sql instance if set to true, a private sql isntance will be created."
@@ -207,6 +213,11 @@ variable "cloudsql_deletion_protection_enabled" {
207213
description = "Whether to enable deletion protection"
208214
}
209215

216+
data "google_compute_network" "existing_vpc_network" {
217+
count = var.private_enable && var.existing_vpc_network != null ? 1 : 0
218+
name = var.existing_vpc_network
219+
}
220+
210221
locals {
211-
private_network = var.enable_private_services ? var.private_network_self_link : var.existing_vpc_network
222+
private_network = var.private_enable ? (var.enable_private_services ? var.private_network_self_link : data.google_compute_network.existing_vpc_network[0].self_link) : null
212223
}

0 commit comments

Comments
 (0)