
Why use Terraform instead of Cloud Deployment Manager?
We can use Cloud Deployment Manager to create a VPC Network, However we have a limitation while using Cloud deployment manager as it is limited to GCP only, the cloud developers who are intended to work on multi-cloud platforms can use Terraform.
Lab Details:
- This lab walks you through GCP VPC Network creation using Terraform.
- The main agenda of this lab is to work on the automation of creating Infrastructure.
- This lab will use Terraform to create a VPC using a Custom subnet.
Lab Tasks:
- Starting Cloud Shell.
- Creating a VPC.
- Destroying the Infrastructure.
Creating a VPC Network:
- Click on the hamburger icon on the top left corner
- Click on the VPC network under the networking section. You will see only one VPC network called Default.

3. Click on the Cloud Shell icon in the top right corner as shown below.
4. Enter the command mkdir terraform to create a directory for the terraform file.
5. Enter the command cd terraform to move to the terraform directory.
6. Enter the command nano main.tf to create a file to initiate the infrastructure code.
7. Enter the below given code which will create a VPC Network, a custom subnet of range 10.0.2.0/29.
provider “google” {
region = “us-central1”
zone = “us-central1-a”
}
resource “google_compute_network” “vpc_network” {
name = “whizlabs-vpc”
auto_create_subnetworks = false
}
resource “google_compute_subnetwork” “us-subnet” {
name = “us-subnet”
ip_cidr_range = “10.0.2.0/29”
region = “us-central1”
network = google_compute_network.vpc_network.name
}
8. After writing the code, Press CTRL + X. Press Y to save the code. press Enter to exit the editor.

9. Enter the command terraform init to initialize the Terraform in the current directory.

10. Enter the command terraform plan to create an execution plan.

11. Enter the command terraform apply to reach the desired state as specified in the configuration.
12. When it asks to confirm, enter yes.
13. You should see the final output as below.


14. Click on the VPC network under the networking section again. You will see our VPC network “wizlabs-vpc” we have just created.

Completion and Conclusion:
- In this lab, you have created a VPC Network using Terraform.
At the beginning, I was still puzzled. Since I read your article, I have been very impressed. It has provided a lot of innovative ideas for my thesis related to gate.io. Thank u. But I still have some doubts, can you help me? Thanks.