Added option to create routes for NVA.

This commit is contained in:
2025-03-31 21:36:30 +02:00
parent e7222382f1
commit bd16823f66
3 changed files with 17 additions and 2 deletions
+11 -1
View File
@@ -1,6 +1,6 @@
data "google_client_config" "default" {} data "google_client_config" "default" {}
resource "google_compute_instance" "vm_hub" { resource "google_compute_instance" "vm" {
name = var.name name = var.name
machine_type = var.machine_type machine_type = var.machine_type
can_ip_forward = var.can_ip_forward 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}" 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
}
+1 -1
View File
@@ -1,3 +1,3 @@
output "vm_internal_ip" { 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
} }
+5
View File
@@ -46,3 +46,8 @@ variable "ssh" {
ssh_user = string ssh_user = string
})) }))
} }
variable "remote_subnets" {
type = list(string)
default = []
}