Added option to enable or disable Cloud NAT.
This commit is contained in:
@@ -23,6 +23,8 @@ module "hub_network" {
|
|||||||
cidr = var.hub.cidr
|
cidr = var.hub.cidr
|
||||||
region = var.hub.region
|
region = var.hub.region
|
||||||
}]
|
}]
|
||||||
|
|
||||||
|
nat = true
|
||||||
}
|
}
|
||||||
|
|
||||||
module "spoke_network" {
|
module "spoke_network" {
|
||||||
@@ -36,6 +38,8 @@ module "spoke_network" {
|
|||||||
region = var.spoke.region
|
region = var.spoke.region
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
nat = true
|
||||||
}
|
}
|
||||||
|
|
||||||
module "hub_to_spoke_peering" {
|
module "hub_to_spoke_peering" {
|
||||||
@@ -61,7 +65,7 @@ module "hub_to_spoke_peering" {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
module "vm-hub" {
|
module "vm_hub" {
|
||||||
source = "./modules/linux-vm"
|
source = "./modules/linux-vm"
|
||||||
|
|
||||||
name = "vm-${var.hub.name}"
|
name = "vm-${var.hub.name}"
|
||||||
@@ -72,7 +76,7 @@ module "vm-hub" {
|
|||||||
depends_on = [module.hub_network]
|
depends_on = [module.hub_network]
|
||||||
}
|
}
|
||||||
|
|
||||||
module "vm-spoke" {
|
module "vm_spoke" {
|
||||||
source = "./modules/linux-vm"
|
source = "./modules/linux-vm"
|
||||||
|
|
||||||
name = "vm-${var.spoke.name}"
|
name = "vm-${var.spoke.name}"
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ resource "google_compute_subnetwork" "subnet" {
|
|||||||
|
|
||||||
# Cloud NAT
|
# Cloud NAT
|
||||||
resource "google_compute_router" "cr" {
|
resource "google_compute_router" "cr" {
|
||||||
|
count = var.nat ? 1 : 0
|
||||||
name = "${var.name}-router"
|
name = "${var.name}-router"
|
||||||
network = var.name
|
network = var.name
|
||||||
|
|
||||||
@@ -22,8 +23,9 @@ resource "google_compute_router" "cr" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resource "google_compute_router_nat" "nat" {
|
resource "google_compute_router_nat" "nat" {
|
||||||
|
count = var.nat ? 1 : 0
|
||||||
name = "${var.name}-nat"
|
name = "${var.name}-nat"
|
||||||
router = google_compute_router.cr.name
|
router = google_compute_router.cr[0].name
|
||||||
nat_ip_allocate_option = "AUTO_ONLY"
|
nat_ip_allocate_option = "AUTO_ONLY"
|
||||||
source_subnetwork_ip_ranges_to_nat = "ALL_SUBNETWORKS_ALL_IP_RANGES"
|
source_subnetwork_ip_ranges_to_nat = "ALL_SUBNETWORKS_ALL_IP_RANGES"
|
||||||
enable_dynamic_port_allocation = true
|
enable_dynamic_port_allocation = true
|
||||||
|
|||||||
@@ -18,3 +18,9 @@ variable "subnets" {
|
|||||||
error_message = "The region for the first subnet must be specified."
|
error_message = "The region for the first subnet must be specified."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
variable "nat" {
|
||||||
|
description = "Enable Cloud NAT for the network."
|
||||||
|
type = bool
|
||||||
|
default = false
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user