Cloud Architecture: Design, Implement, and Manage

Solution for Cloud Architecture: Design, Implement, and Manage. 1 lab: GSP101. Fast copy-paste commands for Google Cloud.

GSP101 — Deploy and Troubleshoot a Website: Challenge Lab

Estimated time: 2 hours 15 minutes

# 🚀 Deploy and Troubleshoot a Website: Challenge Lab | GSP101 > ⚠️ **Disclaimer:** This is an independent, community-made walkthrough created for educational purposes, hands-on practice, and Google Cloud certification preparation. This guide is designed to help learners understand Compute Engine virtual machines, startup scripts, Apache web servers, firewall rules, network tags, and basic website deployment. Always attempt the lab yourself first and follow Google Cloud Skills Boost / Qwiklabs

clear
CYAN='\033[0;96m'
GREEN='\033[0;92m'
YELLOW='\033[0;93m'
BOLD='\033[1m'
RESET='\033[0m'

echo -e "${CYAN}${BOLD}"
echo "    ____        _    _ _            __  ___             "
echo "   / __ \      | |  (_) |          / _| / _ \             "
echo "  | |  | |_ __ | |__  _| |_  ___   | |_ | | | |_ __ ___  "
echo "  | |  | | '__| '_ \| | __| / _ \  |  _|| | | | '_ \ / __| "
echo "  | |__| | |  | |_) | | |_ | (_) | | |  | |_| | |_) \__ \ "
echo "   \____/|_|  |_.__/|_|\__| \___/  |_|   \___/| .__/|___/ "
echo "                                              | |         "
echo "                                              |_|         "
echo -e "${RESET}"

echo -e "${YELLOW}${BOLD}▶ Please enter the exact values assigned to you in the lab manual:${RESET}"
read -p 

\033[0;96m\033[1mEnter Instance Name (e.g., instance-1): \033[0m' INSTANCE_NAME
read -p 

\033[0;96m\033[1mEnter Compute Zone (e.g., us-central1-a): \033[0m' ZONE

export INSTANCE_NAME ZONE
echo -e "\n${GREEN}${BOLD}✓ Variables saved securely. You can now run Command 2.${RESET}"
CYAN='\033[0;96m'
GREEN='\033[0;92m'
YELLOW='\033[0;93m'
BOLD='\033[1m'
RESET='\033[0m'

echo -e "\n${CYAN}${BOLD}▶ Orbit of Ops: Provisioning Cloud Infrastructure...${RESET}"

echo -e "${YELLOW}▶ [Task 1 & 3] Creating Linux VM instance '${INSTANCE_NAME}' with Apache startup script...${RESET}"
gcloud compute instances create $INSTANCE_NAME \
    --zone=$ZONE \
    --machine-type=e2-medium \
    --tags=http-server \
    --metadata=startup-script='#! /bin/bash
apt-get update
apt-get install -y apache2
echo "Hello World!" > /var/www/html/index.html'

echo -e "\n${YELLOW}▶ [Task 2] Creating firewall rule to allow HTTP traffic...${RESET}"
gcloud compute firewall-rules create allow-http-web \
    --direction=INGRESS \
    --action=ALLOW \
    --rules=tcp:80 \
    --source-ranges=0.0.0.0/0 \
    --target-tags=http-server

echo -e "\n${YELLOW}▶ Retrieving External IP Address...${RESET}"
EXTERNAL_IP=$(gcloud compute instances describe $INSTANCE_NAME \
    --zone=$ZONE \
    --format='get(networkInterfaces[0].accessConfigs[0].natIP)')

echo -e "Target IP: ${CYAN}${EXTERNAL_IP}${RESET}"
echo -e "${YELLOW}▶ [Task 4] Waiting for Apache to install and serve content (this takes about 30 seconds)...${RESET}"

max_retries=15
counter=0
while [ $counter -lt $max_retries ]; do
    if curl -s -m 5 "http://$EXTERNAL_IP" | grep -q "Hello World!"; then
        echo -e "\n${GREEN}${BOLD}✓ Success! The web server is active and serving the 'Hello World!' page.${RESET}"
        break
    fi
    echo -n "."
    sleep 5
    counter=$((counter+1))
done

if [ $counter -eq $max_retries ]; then
    echo -e "\n${RED}Timeout reached. The server might still be installing. Please check the URL manually: http://$EXTERNAL_IP${RESET}"
else
    echo -e "\n${CYAN}${BOLD}>>> MISSION COMPLETE! Check all progress bars in Qwiklabs. <<<${RESET}"
fi