From bd16823f66bbc8883ca7a524c4e5c7d6e5bddaa8 Mon Sep 17 00:00:00 2001 From: Slawomir Koszewski Date: Mon, 31 Mar 2025 21:36:30 +0200 Subject: [PATCH] Added option to create routes for NVA. --- modules/linux-vm/main.tf | 12 +++++++++++- modules/linux-vm/outputs.tf | 2 +- modules/linux-vm/variables.tf | 5 +++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/modules/linux-vm/main.tf b/modules/linux-vm/main.tf index b131a09..056bf72 100644 --- a/modules/linux-vm/main.tf +++ b/modules/linux-vm/main.tf @@ -1,6 +1,6 @@ data "google_client_config" "default" {} -resource "google_compute_instance" "vm_hub" { +resource "google_compute_instance" "vm" { name = var.name machine_type = var.machine_type can_ip_forward = var.can_ip_forward @@ -23,3 +23,13 @@ resource "google_compute_instance" "vm_hub" { ssh-keys = "${var.ssh[0].public_key} ${var.ssh[0].ssh_user}" } } + +resource "google_compute_route" "route_to_remote_network" { + count = length(var.remote_subnets) + name = "${var.network_name}-to-${replace(var.remote_subnets[count.index], "/[./]/", "-")}" + project = var.project_id != null ? var.project_id : data.google_client_config.default.project + network = var.network_name + dest_range = var.remote_subnets[count.index] + next_hop_instance = google_compute_instance.vm.id + next_hop_instance_zone = google_compute_instance.vm.zone +} diff --git a/modules/linux-vm/outputs.tf b/modules/linux-vm/outputs.tf index 730f0d0..5410264 100644 --- a/modules/linux-vm/outputs.tf +++ b/modules/linux-vm/outputs.tf @@ -1,3 +1,3 @@ output "vm_internal_ip" { - value = google_compute_instance.vm_hub.network_interface[0].network_ip + value = google_compute_instance.vm.network_interface[0].network_ip } diff --git a/modules/linux-vm/variables.tf b/modules/linux-vm/variables.tf index 0c57cab..3356945 100644 --- a/modules/linux-vm/variables.tf +++ b/modules/linux-vm/variables.tf @@ -46,3 +46,8 @@ variable "ssh" { ssh_user = string })) } + +variable "remote_subnets" { + type = list(string) + default = [] +}