Finished LZ.

This commit is contained in:
2025-04-25 06:45:10 +02:00
parent da3893a912
commit 5968cb558e
6 changed files with 298 additions and 68 deletions
+32
View File
@@ -17,10 +17,26 @@ resource "google_compute_instance" "vm" {
network = var.network_name
subnetwork = var.subnet_name
subnetwork_project = var.project_id != null ? var.project_id : data.google_client_config.default.project
network_ip = var.internal_ip != null ? var.internal_ip : null
dynamic "access_config" {
for_each = var.external_ip_name != null && var.external_ip_name != "AUTO" ? [1] : []
content {
nat_ip = data.google_compute_address.external_ip[0].address
}
}
dynamic "access_config" {
for_each = var.external_ip_name == "AUTO" ? [1] : []
content {
nat_ip = google_compute_address.external_ip[0].address
}
}
}
metadata = {
ssh-keys = "${var.ssh[0].public_key} ${var.ssh[0].ssh_user}"
startup_script = var.startup_script
}
}
@@ -33,3 +49,19 @@ resource "google_compute_route" "route_to_remote_network" {
next_hop_instance = google_compute_instance.vm.id
next_hop_instance_zone = google_compute_instance.vm.zone
}
resource "google_compute_address" "external_ip" {
count = var.external_ip_name == "AUTO" ? 1 : 0
name = "${var.name}-ip"
project = var.project_id != null ? var.project_id : data.google_client_config.default.project
address_type = "EXTERNAL"
address = var.external_ip_name
}
data "google_compute_address" "external_ip" {
count = var.external_ip_name != null && var.external_ip_name != "AUTO" ? 1 : 0
name = var.external_ip_name
project = var.project_id != null ? var.project_id : data.google_client_config.default.project
}
+21
View File
@@ -39,6 +39,20 @@ variable "subnet_name" {
type = string
}
variable "internal_ip" {
description = "The internal IP address of the VM instance."
type = string
nullable = true
default = null
}
variable "external_ip_name" {
description = "The external IP address of the VM instance."
type = string
nullable = true
default = null
}
variable "ssh" {
description = "SSH Key(s) definition"
type = list(object({
@@ -51,3 +65,10 @@ variable "remote_subnets" {
type = list(string)
default = []
}
variable "startup_script" {
description = "Startup script to run on the VM instance."
type = string
nullable = true
default = null
}