Google Cloud: Deploying networks using Terraform

Share At:

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:

  1. This lab walks you through GCP VPC Network creation using Terraform.
  2. The main agenda of this lab is to work on the automation of creating Infrastructure.
  3. This lab will use Terraform to create a VPC using a Custom subnet.

Lab Tasks:

  1. Starting Cloud Shell.
  2. Creating a VPC.
  3. Destroying the Infrastructure.

Creating a VPC Network:

  1. Click on the hamburger icon on the top left corner
  2. 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 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

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 = “”
region = “us-central1”
network =

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:

  1. In this lab, you have created a VPC Network using Terraform.

Happy Learning !!!

Share At:
0 0 votes
Article Rating
Notify of
1 Comment
Oldest Most Voted
Inline Feedbacks
View all comments
16 days ago

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 Thank u. But I still have some doubts, can you help me? Thanks.

Back To Top

Contact Us