0
0
GCPcloud~10 mins

Custom VPC creation in GCP - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Custom VPC creation
Start
Define VPC Name & Region
Specify Subnet Ranges
Create VPC Network
Create Subnets in VPC
Set Firewall Rules (optional)
VPC Ready for Use
This flow shows the steps to create a custom VPC: define name and region, specify subnet IP ranges, create the VPC network, add subnets, optionally set firewall rules, then the VPC is ready.
Execution Sample
GCP
gcloud compute networks create my-custom-vpc --subnet-mode=custom

gcloud compute networks subnets create my-subnet-1 --network=my-custom-vpc --region=us-central1 --range=10.0.1.0/24

gcloud compute firewall-rules create allow-internal --network=my-custom-vpc --allow tcp,udp,icmp --source-ranges=10.0.0.0/16
This code creates a custom VPC, adds a subnet with a specific IP range, and sets a firewall rule to allow internal traffic.
Process Table
StepActionCommandResult
1Create custom VPC networkgcloud compute networks create my-custom-vpc --subnet-mode=customVPC 'my-custom-vpc' created with no subnets
2Create subnet in VPCgcloud compute networks subnets create my-subnet-1 --network=my-custom-vpc --region=us-central1 --range=10.0.1.0/24Subnet 'my-subnet-1' created in 'us-central1' with IP range 10.0.1.0/24
3Create firewall rule to allow internal trafficgcloud compute firewall-rules create allow-internal --network=my-custom-vpc --allow tcp,udp,icmp --source-ranges=10.0.0.0/16Firewall rule 'allow-internal' created allowing tcp, udp, icmp from 10.0.0.0/16
4Verify VPC and subnetgcloud compute networks describe my-custom-vpcShows VPC with custom subnet 'my-subnet-1' and firewall rules
5End-Custom VPC setup complete and ready for use
💡 All steps completed successfully; custom VPC with subnet and firewall rule is ready.
Status Tracker
ResourceInitial StateAfter Step 1After Step 2After Step 3Final State
VPC NetworkNoneCreated (no subnets)Created (no change)Created (no change)Exists with subnet and firewall rules
SubnetNoneNoneCreated with 10.0.1.0/24 in us-central1Created (no change)Exists in VPC
Firewall RulesNoneNoneNoneCreated allowing internal trafficExists and active
Key Moments - 2 Insights
Why do we specify --subnet-mode=custom when creating the VPC?
Because by default, VPCs create automatic subnets in all regions. Using --subnet-mode=custom means no subnets are created automatically, so you can add subnets with your own IP ranges as shown in step 2.
What happens if we skip creating firewall rules after creating the VPC and subnet?
By default, the VPC blocks most traffic. Without firewall rules like in step 3, instances in the subnet cannot communicate internally or externally as desired.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the IP range of the subnet created at step 2?
A10.0.1.0/24
B10.0.0.0/16
C192.168.1.0/24
D172.16.0.0/16
💡 Hint
Check the 'Command' and 'Result' columns in row 2 of the execution table.
At which step is the firewall rule created to allow internal traffic?
AStep 1
BStep 2
CStep 3
DStep 4
💡 Hint
Look for the action mentioning firewall rules in the execution table.
If we omit --subnet-mode=custom in step 1, what changes in the execution?
ANo subnets are created at all
BSubnets are created automatically in all regions
CFirewall rules are created automatically
DThe VPC creation fails
💡 Hint
Refer to the key moment about subnet mode and step 1 in the execution table.
Concept Snapshot
Custom VPC creation in GCP:
- Use 'gcloud compute networks create NAME --subnet-mode=custom' to create empty VPC
- Add subnets with 'gcloud compute networks subnets create' specifying region and IP range
- Set firewall rules to allow traffic as needed
- Custom VPC gives control over subnet IP ranges and network policies
Full Transcript
To create a custom VPC in Google Cloud, first run the command to create a VPC network with subnet mode set to custom. This prevents automatic subnet creation. Next, create subnets inside this VPC by specifying the region and IP address range. Then, add firewall rules to allow internal traffic between instances. The execution table shows each step with commands and results. Variables track the state of the VPC, subnets, and firewall rules as they are created. Key moments clarify why subnet mode custom is important and the role of firewall rules. The visual quiz tests understanding of subnet IP ranges, firewall creation step, and subnet mode effects. The snapshot summarizes the commands and purpose of each step.