Skip to content
Latchkey

gcloud compute networks create: Create a VPC

gcloud compute networks create provisions a VPC network in either auto or custom subnet mode.

Isolated test environments start with their own VPC. Custom subnet mode gives you full control over the CIDR layout; auto mode is the quick default.

What it does

gcloud compute networks create defines a VPC network. With --subnet-mode=auto it creates a subnet per region automatically; with --subnet-mode=custom you add subnets yourself via gcloud compute networks subnets create.

Common usage

Terminal
gcloud compute networks create ci-vpc \
  --subnet-mode=custom
gcloud compute networks subnets create ci-subnet \
  --network=ci-vpc --region=us-central1 \
  --range=10.10.0.0/24

Flags

FlagWhat it does
--subnet-mode auto|customAuto-create regional subnets or manage them yourself
--bgp-routing-mode global|regionalDynamic routing mode for Cloud Router
--mtu <bytes>Maximum transmission unit for the network
--description <text>Free-text description

In CI

Prefer --subnet-mode=custom for reproducible test networks so subnet CIDRs are explicit and do not collide across environments. Pair the new VPC with a firewall rule for the IAP range before trying to SSH into instances on it.

Common errors in CI

"already exists" means the network name is taken in the project. "Invalid value for field 'network.autoCreateSubnetworks'" comes from mixing the deprecated --range flag with subnet-mode. "Required 'compute.networks.create' permission" means the runner lacks roles/compute.networkAdmin.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →