terraform { required_version = ">= 1.0" } provider "google" { project = var.projectID zone = var.zone credentials = file(var.gcpCredentialsFilePath) } locals { sshUserName = "schnarkus" } resource "google_compute_network" "the_network" { name = "the-network" } resource "google_compute_firewall" "gate_guardian" { name = "gate-guardian" network = google_compute_network.the_network.name allow { protocol = "icmp" } allow { protocol = "tcp" ports = ["22", "8080"] # ssh localhost } source_ranges = ["0.0.0.0/0"] } resource "google_compute_instance" "schminstance" { name = "schminstance" machine_type = "e2-micro" boot_disk { initialize_params { image = data.google_compute_image.image.self_link } } network_interface { network = google_compute_network.the_network.name access_config {} } metadata = { ssh-keys = "${local.sshUserName}:${file(var.sshPublicKeyPath)}" } } data "google_compute_image" "image" { family = "ubuntu-2004-lts" project = "ubuntu-os-cloud" } # get ip and publish output "instanceIPv4" { description = "Public IP address of the Google Compute Engine instance" value = google_compute_instance.schminstance.network_interface[0].access_config[0].nat_ip }