You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
This lesson covers the full lifecycle of a Compute Engine VM instance — from creation through configuration to ongoing management. Understanding these operations is essential for running production workloads on GCP.
The most common way to create a VM programmatically is with the gcloud CLI:
gcloud compute instances create web-server-1 \
--zone=europe-west2-a \
--machine-type=e2-standard-4 \
--image-family=ubuntu-2404-lts-amd64 \
--image-project=ubuntu-os-cloud \
--boot-disk-size=50GB \
--boot-disk-type=pd-ssd \
--tags=http-server,https-server \
--metadata=startup-script='#!/bin/bash
apt-get update
apt-get install -y nginx'
resource "google_compute_instance" "web_server" {
name = "web-server-1"
machine_type = "e2-standard-4"
zone = "europe-west2-a"
boot_disk {
initialize_params {
image = "ubuntu-os-cloud/ubuntu-2404-lts-amd64"
size = 50
type = "pd-ssd"
}
}
network_interface {
network = "default"
access_config {} # Ephemeral external IP
}
tags = ["http-server", "https-server"]
}
The Google Cloud Console provides a guided form where you select the zone, machine type, boot disk image, networking, and other options. The Console also shows an estimated monthly cost and can generate the equivalent gcloud or REST command.
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.