LinuxCommandLibrary

gcloud-compute

Manage Google Compute Engine resources

TLDR

List Compute Engine zones

$ gcloud compute zones list
copy

Create a VM instance
$ gcloud compute instances create [instance_name]
copy

Display a VM instance's details
$ gcloud compute instances describe [instance_name]
copy

List all VM instances in a project
$ gcloud compute instances list
copy

Create a snapshot of a persistent disk
$ gcloud compute disks snapshot [disk_name] --snapshot-names [snapshot_name]
copy

Display a snapshot's details
$ gcloud compute snapshots describe [snapshot_name]
copy

Delete a snapshot
$ gcloud compute snapshots delete [snapshot_name]
copy

Connect to a VM instance using SSH
$ gcloud compute ssh [instance_name]
copy

SYNOPSIS

gcloud compute <SUBCOMMAND> [ARGS] [--FLAGS] [--GCLOUD_WIDE_FLAGS]

PARAMETERS

--project
    ID of the Google Cloud project; overrides default.

--zone
    Google Compute Engine zone (e.g., us-central1-a).

--region
    Google Compute Engine region (e.g., us-central1).

--format
    Output format: table/json/yaml/csv/value (default table).

--filter
    Apply filter expression to results.

--limit
    Maximum number of results to return.

--page-size
    Number of results per page.

--sort-by
    Sort results by specified field.

--verbosity
    Logging level: debug/info/warning/error/critical/none/default.

--log-http
    Log all HTTP server interactions to stderr.

--dry-run
    Simulate action without changes (where supported).

--async
    Return immediately without waiting for completion.

DESCRIPTION

gcloud compute is the primary command-line interface in the Google Cloud SDK for interacting with Google Compute Engine (GCE), Google's scalable VM platform. It provides comprehensive control over infrastructure including VM instances, block storage (disks, snapshots, images), networking (VPC networks, firewall rules, routes, external IPs), load balancing (backend services, target proxies, URL maps), and regional resources (zones, regions, machine types).

Users perform operations like provisioning VMs with custom machine types, GPUs, or preemptible instances; configuring autoscaling managed instance groups; resetting Windows passwords; and SSH/SCP access without key management. Operations support async execution, idempotency for scripting, and integration with Terraform/Ansible via JSON output.

Scoped by --project, --zone, or --region flags, it requires IAM roles like Compute Instance Admin. Ideal for automation in CI/CD, it logs HTTP requests for debugging and handles quotas/billing implications.

With ongoing updates, it supports modern features like Confidential Computing, IPv6, and Network Endpoint Groups.

CAVEATS

Requires Google Cloud SDK >=300.0.0, active authentication (gcloud auth login), and IAM permissions (e.g., compute.instances.list). Many operations are asynchronous, billable, incur quotas, and cannot be undone (e.g., delete). Use --dry-run for testing.

KEY SUBCOMMANDS

instances: Manage VMs.
disks: Persistent disks.
firewall-rules: Network firewalls.
networks: VPC/subnets.
images/snapshots: Custom images/backups.
ssh/scp: Secure access.
backend-services: Load balancers. See gcloud compute --help for full list.

EXAMPLES

gcloud compute instances create my-vm --zone=us-central1-a --machine-type=e2-medium --image-family=debian-11 --image-project=debian-cloud
gcloud compute ssh my-vm --zone=us-central1-a
gcloud compute instances list --filter="name:my-vm" --format=yaml

INSTALLATION & SETUP

Install: curl https://sdk.cloud.google.com | bash, then gcloud init. Update: gcloud components update.

HISTORY

Introduced in 2013 with Google Cloud SDK v1.0 alongside Compute Engine public beta. Evolved with GCE features: live migration (2015), preemptible VMs (2016), autoscaler v2 (2018), Confidential VMs (2020). SDK unified under gcloud in 2015, replacing gcutil.

SEE ALSO

gcloud(1), ssh(1), gsutil(1)

Copied to clipboard