Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Terraform for Google Cloud Essential Guide

You're reading from   Terraform for Google Cloud Essential Guide Learn how to provision infrastructure in Google Cloud securely and efficiently

Arrow left icon
Product type Paperback
Published in Jan 2023
Publisher Packt
ISBN-13 9781804619629
Length 180 pages
Edition 1st Edition
Arrow right icon
Author (1):
Arrow left icon
Bernd Nordhausen Bernd Nordhausen
Author Profile Icon Bernd Nordhausen
Bernd Nordhausen
Arrow right icon
View More author details
Toc

Table of Contents (16) Chapters Close

Preface 1. Part 1: Getting Started: Learning the Fundamentals
2. Chapter 1: Getting Started with Terraform on Google Cloud FREE CHAPTER 3. Chapter 2: Exploring Terraform 4. Chapter 3: Writing Efficient Terraform Code 5. Chapter 4: Writing Reusable Code Using Modules 6. Chapter 5: Managing Environments 7. Part 2: Completing the Picture: Provisioning Infrastructure on Google Cloud
8. Chapter 6: Deploying a Traditional Three-Tier Architecture 9. Chapter 7: Deploying a Cloud-Native Architecture Using Cloud Run 10. Chapter 8: Deploying GKE Using Public Modules 11. Part 3: Wrapping It Up: Integrating Terraform with Google Cloud
12. Chapter 9: Developing Terraform Code Efficiently 13. Chapter 10: Google Cloud Integration 14. Index 15. Other Books You May Enjoy

Terraform language

As mentioned, the Terraform language is based on HCL. The most basic construct is a block, defined as a “container for other content” (https://developer.hashicorp.com/terraform/language/syntax/configuration#blocks). For example, the preceding code block is of the type resource. A resource block has two labels. The first label consists of the provider and resource name. For example, the resource label for a Google compute engine is google_compute_instance, whereas the label for an AWS E2 instance is aws_instance. The second label in a resource block is the ID, the name you give so that Terraform can uniquely identify each resource. Please note that no two resources can have the same name. So, if you want to provision two VMs, you define two resource blocks, each of type google_compute_instance, and each with a unique name.

The body of the block is nested within {}. Blocks can have nested blocks. In the preceding code example, there are two nested blocks, boot_disk (which in itself has a nested block called initialize_params) and network_interface.

While the syntax for Terraform is the same, each cloud provider has its unique resources and data source definitions. The Terraform documentation for Google Cloud is at https://registry.terraform.io/providers/hashicorp/google/latest/docs. You see that all resources and data sources start with the google keyword. In general, it is followed by the name of the equivalent gcloud command. Thus, the resource to create a compute instance is named google_compute_instance, whereas the resource to provision a SQL database instance is named google_sql_database_instance.

Looking at the documentation, you can see the current Google services that are currently supported. More are added as Google Cloud introduces new services. We recommend you bookmark the documentation as you have to refer to it frequently.

In the first part of this book, we use only a few Google Cloud resources as we want to concentrate on the language. We design complex architectures using additional Google Cloud services in the second part. But first, let’s look at the steps involved in using Terraform.

You have been reading a chapter from
Terraform for Google Cloud Essential Guide
Published in: Jan 2023
Publisher: Packt
ISBN-13: 9781804619629
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime