From 1dab60aff372dc8db6077fd5ad53182dac5e2286 Mon Sep 17 00:00:00 2001 From: 08sm80 Date: Tue, 24 Sep 2024 15:13:19 +0530 Subject: [PATCH] add networks.tf --- main.tf | 27 ++++++++++++--------------- networks.tf | 11 +++++++++++ templates/startup.sh | 5 +++++ 3 files changed, 28 insertions(+), 15 deletions(-) create mode 100644 networks.tf create mode 100644 templates/startup.sh diff --git a/main.tf b/main.tf index 3b73bd3..03543f0 100644 --- a/main.tf +++ b/main.tf @@ -1,17 +1,6 @@ # Networks config - -data "google_compute_network" "default" { # existing default network - name = "default" -} - -data "google_compute_network" "vpc1" { # existing custom network - name = "vpc1" -} - -data "google_compute_subnetwork" "vpc1_sn2" { - name = "vpc1-sn2" -} +# moved to networks.tf # Compute @@ -45,10 +34,18 @@ resource "google_compute_instance" "gce_vm1" { } metadata = { - ninja = "level-1" + ninja = "level-1" + enable-oslogin = false + startup-script = <<-EOT +#! /bin/bash +sudo apt update +sudo apt install busybox -y +echo "Hello, World" > index.xhtml +nohup busybox httpd -f -p 8080 & +EOT } - metadata_startup_script = "echo hi > /test.txt" + service_account { # Google recommends custom service accounts that have cloud-platform scope and permissions granted via IAM Roles. @@ -63,7 +60,7 @@ resource "google_compute_firewall" "basic_access" { name = "basic-access" allow { protocol = "TCP" - ports = ["80", "443", "22"] + ports = ["80", "443", "22", "8080"] } source_ranges = ["0.0.0.0/0"] } diff --git a/networks.tf b/networks.tf new file mode 100644 index 0000000..2b38d06 --- /dev/null +++ b/networks.tf @@ -0,0 +1,11 @@ +data "google_compute_network" "default" { # existing default network + name = "default" +} + +data "google_compute_network" "vpc1" { # existing custom network + name = "vpc1" +} + +data "google_compute_subnetwork" "vpc1_sn2" { + name = "vpc1-sn2" +} diff --git a/templates/startup.sh b/templates/startup.sh new file mode 100644 index 0000000..5063c6a --- /dev/null +++ b/templates/startup.sh @@ -0,0 +1,5 @@ +#!/bin/bash +set -e -x -u -o pipefail + +echo "Hello, World" > index.xhtml +nohup busybox httpd -f -p 8080 &