Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Terraform for Google Cloud Essential Guide
  • Table Of Contents Toc
  • Feedback & Rating feedback
Terraform for Google Cloud Essential Guide

Terraform for Google Cloud Essential Guide

By : Bernd Nordhausen
4.7 (11)
close
close
Terraform for Google Cloud Essential Guide

Terraform for Google Cloud Essential Guide

4.7 (11)
By: Bernd Nordhausen

Overview of this book

Google Cloud has adopted Terraform as the standard Infrastructure as Code tool. This necessitates a solid understanding of Terraform for any cloud architect or engineer working on Google Cloud. Yet no specific resources are available that focus on how to use Terraform on Google Cloud. This is the first book that teaches Terraform specifically for Google Cloud. You will take a journey from the basic concepts through to deploying complex architectures using Terraform. Using extensive code examples, you will receive guidance on how to authenticate Terraform in Google Cloud. As you advance, you’ll get to grips with all the essential concepts of the Terraform language as applied to Google Cloud and deploy complete working architectures at the push of a button. Finally, you’ll also be able to improve your Terraform workflow using Google Cloud native and third-party tools. By the end of this Terraform book, you will have gained a thorough understanding of Terraform and how to use it on Google Cloud, and be able to develop effective Terraform code, build reusable code, and utilize public domain Terraform modules to deploy on Google Cloud faster and more securely.
Table of Contents (16 chapters)
close
close
1
Part 1: Getting Started: Learning the Fundamentals
7
Part 2: Completing the Picture: Provisioning Infrastructure on Google Cloud
11
Part 3: Wrapping It Up: Integrating Terraform with Google Cloud

Terraform workflow

A basic Terraform workflow consists of the following two steps:

  1. Init
  2. Apply

In this first step, terraform init initializes Terraform and downloads all the necessary configuration files. You see that after init is run, there is a hidden directory named .terraform. This directory is where Terraform stores various configuration files. You must run the initialization step every time you write a new configuration file. Don’t worry; you can run this command multiple times, and you learn over time when you need to rerun it. If in doubt, run it again as it only takes a few seconds.

The second step, terraform apply, consists of two phases. First, Terraform creates an execution plan, then it executes this plan. The execution plan is an internal plan of the actions Terraform will perform and in which order. Terraform outputs this plan, including a summary of how many resources will be added, changed, and destroyed. You should always review this output carefully. Once you have confirmed that the plan does what you intended, you can confirm, and Terraform actually provisions the cloud resources.

You can also run the two phases explicitly by running terraform plan, saving the plan in a file, and then running terraform apply against that file, like so:

$ terraform plan --out=plan
$ terraform apply plan

This is often done in CI/CD pipelines, and we will return to it later.

One of the advantages of IaC is that you can quickly remove resources. This is not only useful during the development phase, as you can test things quickly, but it also can help you save costs. At the end of the workday, you can remove all the resources and reprovision them the next day. To destroy resources in Terraform, simply execute the following command:

$ terraform destroy

Now, after you have run terraform destroy and run terraform apply twice, you’ll notice that the second time you run terraform apply, Terraform reports no changes, and no action is performed. The next chapter discusses how Terraform decides what actions to take.

There are many more Terraform commands, and we introduce them throughout the book. For now, remember the following four commands:

  • terraform init to initialize
  • terraform plan to view and create a Terraform plan
  • terraform apply to actually provision the resources
  • terraform destroy to remove all resources

Now that we have described the basic workflow of Terraform and shown how you run Terraform in Google Cloud Shell, let’s look at the different ways of running Terraform on your local computer.

bookmark search playlist download font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY