Skip to content

Instantly share code, notes, and snippets.

@tsmx
Last active August 5, 2021 10:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsmx/72692988dee969e326d486931f5cbd91 to your computer and use it in GitHub Desktop.
Save tsmx/72692988dee969e326d486931f5cbd91 to your computer and use it in GitHub Desktop.
GCP: instance template with multiple NIC's

GCP Compute Engine instance template creation with multiple NIC's and health-check FW rule

An instance template with more than one NIC obviously can't be created in the GCP web console. But it could easily be achieved using the gcloud CLI with consecutive --network-interface options.

gcloud compute --project=YOUR_PROJECT instance-templates create multi-nic-vm-template --machine-type=e2-micro --network-interface=subnet=projects/YOUR_PROJECT/regions/europe-west3/subnetworks/my-subnet-1,no-address --network-interface=subnet=projects/YOUR_PROJECT/regions/europe-west3/subnetworks/my-subnet-2,no-address --maintenance-policy=MIGRATE --image=my-image-1 --image-project=YOUR_PROJECT --boot-disk-size=10GB --boot-disk-type=pd-standard --boot-disk-device-name=instance-template-1 --no-shielded-secure-boot --shielded-vtpm --shielded-integrity-monitoring --reservation-affinity=any --tags=allow-health-check

In this example I specified two subnets that belong to different VPC's.

Assumptions for the example:

  • ID of the project: YOUR_PROJECT
  • region: europe-west-3
  • subnet for first network interface: my-subnet-1
  • subnet for second network interface: my-subnet-2
  • both NIC's should not have a public IP (no_address)
  • template created from image: my-image-1
  • a firewall rule tagged with allow-health-check is in place for the VPC network assigned to the first NIC to allow traffic for TCP port 80 from sources 130.211.0.0/22 and 35.191.0.0/16 to enable GCP health checks for auto-scaling instance groups (see health-check firewall rules)

For more details refer to the documentation of the network-interface option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment