Added conditional project designation feature for relevant modules.

This commit is contained in:
2025-03-31 21:17:33 +02:00
parent fadc7573cb
commit e7222382f1
13 changed files with 89 additions and 20 deletions
+6
View File
@@ -1,13 +1,17 @@
data "google_client_config" "default" {}
# VPC
resource "google_compute_network" "network" {
name = var.name
auto_create_subnetworks = false
project = var.project_id != null ? var.project_id : data.google_client_config.default.project
}
# Subnets
resource "google_compute_subnetwork" "subnet" {
count = length(var.subnets)
name = var.subnets[count.index].name
project = var.project_id != null ? var.project_id : data.google_client_config.default.project
ip_cidr_range = var.subnets[count.index].cidr
region = var.subnets[count.index].region != null ? var.subnets[count.index].region : var.subnets[0].region
network = google_compute_network.network.id
@@ -18,6 +22,7 @@ resource "google_compute_router" "cr" {
count = var.nat ? 1 : 0
name = "${var.name}-router"
network = var.name
project = var.project_id != null ? var.project_id : data.google_client_config.default.project
depends_on = [google_compute_network.network]
}
@@ -25,6 +30,7 @@ resource "google_compute_router" "cr" {
resource "google_compute_router_nat" "nat" {
count = var.nat ? 1 : 0
name = "${var.name}-nat"
project = var.project_id != null ? var.project_id : data.google_client_config.default.project
router = google_compute_router.cr[0].name
nat_ip_allocate_option = "AUTO_ONLY"
source_subnetwork_ip_ranges_to_nat = "ALL_SUBNETWORKS_ALL_IP_RANGES"
+7
View File
@@ -3,6 +3,13 @@ variable "name" {
type = string
}
variable "project_id" {
description = "The GCP project ID. If not provided, the default project will be used."
type = string
nullable = true
default = null
}
# A Cloud NAT will be created in the same region as the first subnet.
variable "subnets" {
description = "A list of subnets with names and CIDRs."