Google Cloud: Automating the Deployment of Infrastructure Using Terraform

Share At:

Terraform enables us to safely and predictably create, change, and improve infrastructure. It is an open-source tool that codifies APIs into declarative configuration files that can be shared among team members, treated as code, edited, reviewed, and versioned.

In this lab, we will create a Terraform configuration with a module to automate the deployment of Google Cloud infrastructure. Specifically, we will deploy one auto mode network with a firewall rule and two VM instances, as shown in this diagram:

Set up Terraform and Cloud Shell. Create mynetwork and its resources

Configure your Cloud Shell environment to use Terraform. Install Terraform.

Terraform is now integrated into Cloud Shell. Verify which version is installed.

1. In the Cloud Console, click Activate Cloud Shell.

2. If prompted, click Continue.

3. To confirm that Terraform is installed, run the following command:

terraform — version

Don’t worry if you get a warning that the version of Terraform is out of date.

Terraform is distributed as a binary package for all supported platforms and architectures, and Cloud Shell uses Linux 64-bit.

4. To create a directory for your Terraform configuration, run the following command:

mkdir tfinfra

5. Now change to this directory called “tfinfra” and create 2 files named “” and “” like below:

6. Now create a new directory inside tfinfra called “instance” and change to this directory. create a file named “” as below:

7. You should have the following folder structure in Cloud Shell:

8. Now Go back to the “tfinfra” directory and Initialize the terraform with below command:

terraform init

9. To create an execution plan, run the following command:

terraform plan

10. To apply the desired changes, run the following command. To confirm the planned actions when prompted, type “yes”

terraform apply

Congratulations !! Your deployment is completed.

Verify your deployment

Verify your network in the Cloud Console

  1. In the Cloud Console, on the Navigation menu , click VPC network > VPC networks.

2. View the mynetwork VPC network with a subnetwork in every region.

3. On the Navigation menu, click VPC network > Firewall.

4. View the mynetwork-allow-http-ssh-rdp-icmp firewall rule for mynetwork.

Verify your VM instances in the Cloud Console

  1. On the Navigation menu, click Compute Engine > VM instances.

2. View the mynet-us-vm and mynet-eu-vm instances.

3. Click SSH to launch a terminal and connect, you should be good

That Concludes our tutorial for Automating the Deployment of Infrastructure Using Terraform.

Download Link for, and

Happy Learning !!!

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

I have read your article carefully and I agree with you very much. This has provided a great help for my thesis writing, and I will seriously improve it. However, I don’t know much about a certain place. Can you help me?

бнанс зареструватися

I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.

Back To Top

Contact Us