Skip to content

Commit 2f6b837

Browse files
authored
Merge pull request #75 from remerge/DATA-897-terraform-create-a-cloud-sql-instance-in-dwh-v2
add variable to enable adding authorised networks for cloud_sql
2 parents 09b88b3 + 3528603 commit 2f6b837

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

google/sql/postgresql/main.tf

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,14 @@ resource "google_sql_database_instance" "main" {
2323
ip_configuration {
2424
private_network = var.network
2525
ipv4_enabled = var.ipv4_enabled
26-
ssl_mode = "ALLOW_UNENCRYPTED_AND_ENCRYPTED"
26+
ssl_mode = var.ipv4_enabled ? "ENCRYPTED_ONLY" : "ALLOW_UNENCRYPTED_AND_ENCRYPTED"
27+
dynamic "authorized_networks" {
28+
for_each = var.ipv4_enabled ? var.authorized_networks : []
29+
content {
30+
name = authorized_networks.value.name
31+
value = authorized_networks.value.value
32+
}
33+
}
2734
}
2835

2936
availability_type = "REGIONAL"

google/sql/postgresql/variables.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,12 @@ variable "ipv4_enabled" {
4646
type = bool
4747
default = false
4848
}
49+
50+
variable "authorized_networks" {
51+
description = "List of authorized networks for public access. Each object must have 'name' and 'value' (subnet/CIDR)."
52+
type = list(object({
53+
name = string
54+
value = string
55+
}))
56+
default = []
57+
}

0 commit comments

Comments
 (0)