Startup script on GCP Virtual instance in Simple terms

Let us talk about startup script on Gcp virtual instance. I am creating a new Virtual instance & leaving most of the defaults & allow http traffic on firewall so that I can ssh

Expand management & Scroll down a bit you should see the option to enter your startup script.

I am going to specify a script, that automatically installs apache2 & sets up the simple page.

#! /bin/bash
apt update
apt -y install apache2
echo "Hello world from $(hostname) $(hostname -i)" > /var/www/html/index.html

Once we create this virtual instance the script will automatically run and install apache2 and update the index.html file.