GCP | How to set up and use Terraform for GCP

Terraform is a tool for building, changing, and versioning infrastructure safely and efficiently. Below are the steps for setting up Terraform for Google Cloud Platform.

We would be using Visual Studio code for writing Terraform code, if you don't have VS code available than install it or use any other code editor of your choice

Before using Terraform for automating Google Cloud Infra tasks, we need to have service account for GCP authentication and locally installed Terraform executable, refer below steps for these.

  • Create a folder on desktop and open it with VS Code, for this post folder with name "terraform" is created.
  • Open "New Terminal" in "terraform" and run below command.
  • Create new file "provider.tf" inside folder "terraform" and write below code.
  • Create new file "createvm.tf" inside folder "terraform" and write below code.
  • In Terminal and run below command for formatting Terraform files.
  • Run again "terraform init" command.
  • Run "terraform plan" command to check execution plan.
  • Finally run "terraform apply" command to create VM on GCP.
  • After performing all the steps you should see a VM with name "gcptutorials-tf" in GCP.

  • Follow US on Twitter:

    Category: GCP

    Python For Beginners