Create Custom VPC with Subnets Configuration (Solution)

Create Custom VPC with Subnets Configuration (Solution)

Overview

  • Labs are timed and cannot be paused. The timer starts when you click Start Lab.

  • The included cloud terminal is preconfigured with the gcloud SDK.

  • Use the terminal to execute commands and then click Check my progress to verify your work.

Challenge scenario

  • You have an existing project with the default VPC. As per the VPC best practice you have decided to move to a custom VPC for better network isolation and control.

  • Your task is to delete default VPC and create custom VPC with two subnets in us-central1 and asia-southeast1 in provided time frame.

Click Check my progress to verify the objective.

Custom VPC with two subnets


Solution of Lab

curl -LO raw.githubusercontent.com/ePlus-DEV/storage/refs/heads/main/labs/create-custom-vpc-with-subnets-configuration-solution/lab.sh
source lab.sh

Script Alternative


gcloud compute firewall-rules list --filter="network=default" --format="value(name)" | xargs -r -I {} gcloud compute firewall-rules delete {} --quiet && \
gcloud compute networks delete default --quiet && \
gcloud compute networks create custom-vpc --subnet-mode=custom && \
gcloud compute networks subnets create custom-subnet-us --network=custom-vpc --region=us-central1 --range=10.0.1.0/24 && \
gcloud compute networks subnets create custom-subnet-asia --network=custom-vpc --region=asia-southeast1 --range=10.0.2.0/24