Google Cloud Platform (GCP) makes it incredibly easy to spin up a Virtual Machine (VM) in just a few clicks.
In this post, I’ll guide you through creating a basic Compute Engine VM instance, perfect for beginners getting started with GCP.
1️⃣ Enable the Compute Engine API
Before you can create a VM, make sure the Compute Engine API is enabled for your project.
Go to:
Google Cloud Console → APIs & Services → Enable APIs → Search "Compute Engine API" → Enable
2️⃣ Create a New VM Instance
Navigate to:
Google Cloud Console → Compute Engine → VM Instances → Create Instance
3️⃣ Fill in the VM Details
Basic Info
- Name: demo1-vm
- Labels > environment: dev
- Region: us-central1
- Zone: us-central1-a
Machine Configuration
- Series: E2
- Machine Type: e2-micro (free-tier eligible)
Operating system and storage
Availability Policies
- VM Provisioning Model: Standard
- Display Device: ✅ Checked
- Confidential VM Service: ❌ Unchecked (default)
- Container: ❌ Unchecked (default)
Boot Disk
Leave defaults (Debian/Ubuntu image works fine for now)
Identity and API Access
- Service Account: Compute Engine default
- Access Scopes: Allow default access
Firewall
✅ Allow HTTP Traffic (so you can host a simple web server later)
Advanced Options
Leave default for now (we’ll cover these in detail in future posts)
4️⃣ Create the VM
Click Create and wait for GCP to provision your instance.
In a few moments, you’ll have your VM ready to connect via SSH or use for your workloads.
5️⃣ Connect to the VM via SSH
Go to:
Google Cloud Console → Compute Engine → VM Instances → demo1-vm
Click SSH → Open in browser window
🛠 What Happens in the Background?
When you open an SSH connection in the browser, Google Cloud:
- Generates temporary SSH keys in the background
- Transfers the public key to your VM
- Appends the public key to:
~/.ssh/authorized_keys
- Starts the SSH session directly in your browser tab
You can verify the key by running inside the VM:
cat ~/.ssh/authorized_keys
6️⃣ Create the Web Server Install Script
Let’s create a simple script that installs nginx and sets up a test page.
nano webserver-install.sh
Add the below content into the webserver-install.sh
#!/bin/bash
sudo apt install -y telnet
sudo apt install -y nginx
sudo systemctl enable nginx
sudo chmod -R 755 /var/www/html
HOSTNAME=$(hostname)
sudo echo "<!DOCTYPE html> <html> <body style='background-color:rgb(250, 210, 210);'> <h1>Welcome to Latchu@DevOps - WebVM App1 </h1> <p><strong>VM Hostname:</strong> $HOSTNAME</p> <p><strong>VM IP Address:</strong> $(hostname -I)</p> <p><strong>Application Version:</strong> V1</p> <p>Google Cloud Platform - Demos</p> </body></html>" | sudo tee /var/www/html/index.html
Save and exit (CTRL+O, CTRL+X), then make it executable:
chmod +x webserver-install.sh
./webserver-install.sh
7️⃣ Access the Web Server
Find your VM’s External IP in the VM details page
Open your browser and visit:
http://<external-ip-of-vm>