#Thanks to Remo #!/bin/bash # Update and install Apache2 apt update apt install -y apache2 # Start and enable Apache2 systemctl start apache2 systemctl enable apache2 # GCP Metadata server base URL and header METADATA_URL="http://metadata.google.internal/computeMetadata/v1" METADATA_FLAVOR_HEADER="Metadata-Flavor: Google" # Use curl to fetch instance metadata local_ipv4=$(curl -H "${METADATA_FLAVOR_HEADER}" -s "${METADATA_URL}/instance/network-interfaces/0/ip") zone=$(curl -H "${METADATA_FLAVOR_HEADER}" -s "${METADATA_URL}/instance/zone") project_id=$(curl -H "${METADATA_FLAVOR_HEADER}" -s "${METADATA_URL}/project/project-id") network_tags=$(curl -H "${METADATA_FLAVOR_HEADER}" -s "${METADATA_URL}/instance/tags") # Create a simple HTML page and include instance details cat < /var/www/html/index.html

Welcome to your custom website.

Created with a direct input startup script!

Instance Name: $(hostname -f)

Instance Private IP Address: $local_ipv4

Zone: $zone

Project ID: $project_id

Network Tags: $network_tags

EOF