kubernetes_ip_demo/terraform/user_machine.tf
Tom Alexander 6932701c21
Demonstrate conservative RFC1918 IP address use on GKE.
This is a terraform config demonstrating spinning up 14 clusters in only a /26 (64 addresses) to demonstrate the GKE clusters do not need to consume large amounts of RFC1918 IP addresses.
2025-03-15 15:33:02 -04:00

59 lines
1.6 KiB
HCL

#
# This machine exists for the end-user to ssh into and access
# internal-only ingresses.
#
output "user_machine_ssh_command" {
description = "Command to launch an ssh shell on the user machine."
value = "gcloud compute ssh --zone '${var.zone}' '${google_compute_instance.user_machine.name}' --project '${google_project.project.project_id}'"
}
resource "google_service_account" "user_machine" {
project = google_project.project.project_id
account_id = "user-machine"
display_name = "Custom SA for User Machine VM Instance"
}
resource "google_compute_instance" "user_machine" {
project = google_project.project.project_id
name = "user-machine"
machine_type = "g1-small"
zone = var.zone
tags = ["allow-iap-ssh"]
boot_disk {
initialize_params {
image = "debian-cloud/debian-12"
}
}
network_interface {
network = google_compute_network.default.id
subnetwork = google_compute_subnetwork.default.id
}
service_account {
email = google_service_account.user_machine.email
scopes = ["cloud-platform"]
}
metadata = var.ssh_key != null ? {
ssh-keys = var.ssh_key
} : {}
depends_on = [google_project_service.service["compute"], google_project_service.service["logging"]]
}
resource "google_compute_firewall" "allow_iap_ssh" {
project = google_project.project.project_id
name = "allow-iap-ssh"
network = google_compute_network.default.id
direction = "INGRESS"
allow {
protocol = "tcp"
ports = ["22"]
}
source_ranges = ["35.235.240.0/20"]
target_tags = ["allow-iap-ssh"]
}