Skip to content

VPCs and NAT

A VPC is a private network in one region. Droplets, Kubernetes nodes, database clusters and load balancers in it reach each other on private addresses, and traffic between them never leaves DigitalOcean’s network. Every region has a default VPC, which resources join when you don’t name one. Peering joins two VPCs, and a NAT gateway gives machines in a VPC one shared public address for outbound traffic.

const vpc = yield* DigitalOcean.Vpc("AppVpc", { region: "nyc3", ipRange: "10.40.0.0/20" });

Pass vpc.vpcId as vpcUuid on a Droplet, Kubernetes cluster, database cluster or load balancer in the same region. Without ipRange, DigitalOcean picks one that doesn’t overlap the team’s other VPCs.

yield* DigitalOcean.VpcPeering("AppToData", { vpcIds: [app.vpcId, data.vpcId] });

Peered VPCs, even in different regions, reach each other on private addresses.

yield* DigitalOcean.NatGateway("Egress", { region: "nyc3", vpcIds: [vpc.vpcId] });
  • The first VPC in a region becomes that region’s default, and a default VPC can’t be deleted. Create VPCs in regions where the team already has one, or expect the first to stay.
  • A VPC’s region and IP range can’t change: changing them creates a new VPC.
  • A VPC with members can’t be deleted; destroy waits until they’re gone.