Added option to enable or disable Cloud NAT.

This commit is contained in:
2025-03-31 10:29:07 +02:00
parent 93537e5da5
commit 5b0c5d33eb
3 changed files with 15 additions and 3 deletions
+3 -1
View File
@@ -15,6 +15,7 @@ resource "google_compute_subnetwork" "subnet" {
# Cloud NAT
resource "google_compute_router" "cr" {
count = var.nat ? 1 : 0
name = "${var.name}-router"
network = var.name
@@ -22,8 +23,9 @@ resource "google_compute_router" "cr" {
}
resource "google_compute_router_nat" "nat" {
count = var.nat ? 1 : 0
name = "${var.name}-nat"
router = google_compute_router.cr.name
router = google_compute_router.cr[0].name
nat_ip_allocate_option = "AUTO_ONLY"
source_subnetwork_ip_ranges_to_nat = "ALL_SUBNETWORKS_ALL_IP_RANGES"
enable_dynamic_port_allocation = true
+6
View File
@@ -18,3 +18,9 @@ variable "subnets" {
error_message = "The region for the first subnet must be specified."
}
}
variable "nat" {
description = "Enable Cloud NAT for the network."
type = bool
default = false
}