Chapter 8. Infrastructure as Code Using Terraform
In this chapter, I’ll show you how to work with Terraform, an infrastructure as code (IaC) tool. Terraform lets you recreate your entire project using one command. If you put your infrastructure specification in source control, you can easily manage changes and collaborate with your team.
Personally, I wouldn’t want to do any project without IaC. It is convenient to run terraform apply and have everything set up correctly, especially when your application grows beyond “Hello World” and you add more Cloud Run services, IAM configuration, links to Memorystore through a VPC Connector, and Cloud SQL, to name a few. You can run into challenges if you are setting everything up using one-off commands or scripts.
I’ll introduce IaC, help you get started with Terraform, and help you discover the Terraform workflow so you can figure out if it works for you.
What Is Infrastructure as Code?
Infrastructure is an abstract term that can have multiple interpretations, so I want to make sure our definitions are aligned. This is what I mean when I use these terms:
- Infrastructure
- All cloud resources that need to be present and configured when you want to create your entire application from scratch.
- Cloud resources
- Resources you can create through the Google Cloud API (using gcloud or the web console) are cloud resources. Examples are a Cloud Run service, a VPC Connector, and a Cloud SQL instance, but also a Google Cloud Project, a service account, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access