How to do it...

Initially, the instances in the subnets created will not have connectivity. We'll setup a VPN connection and verify that we are able to establish a connection between the instances in the two separate networks:

  1. Let's create a VM in the subnet alpha-subnet-vpn with default attributes:
gcloud beta compute instances create "alpha-instance" --zone"us-east1-c" --machine-type "n1-standard-1" --subnet"alpha-subnet-vpn" --image "debian-9-stretch-v20171213"--image-project "debian-cloud"
  1. Similarly, let's create another VM in the beta-subnet-vpn:
gcloud beta compute instances create "beta-instance" --zone"us-central1-c" --machine-type "n1-standard-1" --subnet"beta-subnet-vpn" --image "debian-9-stretch-v20171213"--image-project "debian-cloud" ...

Get Google Cloud Platform Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.