Terraform for Google Cloud Essential Guide

Book description

Become an expert in Terraform on Google Cloud by using Infrastructure as Code for provisioning multiple yet consistent environments to increase productivity in no time

Key Features

  • Get up and running with Terraform on Google Cloud
  • Learn Terraform concepts using Google Cloud code examples
  • Apply Terraform to deploy realistic multi-tiered architectures quickly and repeatedly

Book Description

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.

What you will learn

  • Authenticate Terraform in Google Cloud using multiple methods
  • Write efficient Terraform code
  • Use modules to share Terraform templates
  • Manage multiple environments in Google Cloud
  • Apply Terraform to deploy multi-tiered architectures
  • Use public modules to deploy complex architectures quickly
  • Integrate Terraform into your Google Cloud environment

Who this book is for

This book is for Google Cloud architects and engineers who want to increase their productivity by using Terraform to automate the provisioning of Google Cloud deployments. A basic understanding of Google Cloud, such as the ability to provision resources using the Google Cloud console and using Cloud Shell, is assumed. Certification in Google Cloud is not required but helpful.

Table of contents

  1. Terraform for Google Cloud Essential Guide
  2. Contributors
  3. About the author
  4. About the reviewer
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Download the color images
    6. Conventions used
    7. Get in touch
    8. Share Your Thoughts
    9. Download a free PDF copy of this book
  6. Part 1: Getting Started: Learning the Fundamentals
  7. Chapter 1: Getting Started with Terraform on Google Cloud
    1. Technical requirements
    2. The rise of DevOps
      1. Infrastructure as Code
      2. Terraform
    3. Running Terraform in Google Cloud Shell
    4. Terraform language
    5. Terraform workflow
    6. Running Terraform in your local environment
      1. Authentication using a service account
      2. Authentication using a service account and environment variable
      3. Service account impersonation
    7. Parameterizing Terraform
    8. Comparing authentication methods
    9. Summary
  8. Chapter 2: Exploring Terraform
    1. Technical requirements
    2. Understanding the Terraform state
      1. Interacting with the Terraform state
      2. Understanding destructive changes
      3. Avoiding configuration drift
      4. Additional state commands
    3. Using the backend state
    4. Understanding Terraform meta-arguments
      1. The provider meta-argument
      2. The count meta-argument
      3. The for_each meta-argument
      4. The depends_on meta-argument
      5. The lifecycle meta-argument
    5. Using the self_link attribute
    6. Summary
  9. Chapter 3: Writing Efficient Terraform Code
    1. Technical requirements
    2. Terraform types and values
    3. Using Terraform expressions
      1. Dynamic blocks
      2. Conditional expressions
    4. Terraform functions
    5. Referencing existing data using data sources
    6. Using output values
    7. Tips to develop Terraform code efficiently
    8. Summary
  10. Chapter 4: Writing Reusable Code Using Modules
    1. Technical requirements
    2. Building modules
    3. Writing flexible modules
    4. Sharing modules using Google Cloud Storage and Git repositories
    5. Using public module repositories
    6. Summary
  11. Chapter 5: Managing Environments
    1. Technical requirements
    2. Google resource hierarchy
    3. Using workspaces to manage environments
    4. Using a directory structure to manage environments
    5. Using remote states
    6. Using template files
    7. Managing Terraform at scale
    8. Summary
  12. Part 2: Completing the Picture: Provisioning Infrastructure on Google Cloud
  13. Chapter 6: Deploying a Traditional Three-Tier Architecture
    1. Technical requirements
    2. Overview
    3. Laying the foundation
    4. Provisioning the database
    5. Provisioning a MIG and global load balancer
    6. Summary
  14. Chapter 7: Deploying a Cloud-Native Architecture Using Cloud Run
    1. Technical requirements
    2. Overview
    3. Provisioning Redis and connecting it via a VPC connector
    4. Using Terraform to configure a flexible load balancer for Cloud Run
    5. Using Terraform to provision Cloud Run services
    6. To Terraform or not to Terraform
    7. Summary
  15. Chapter 8: Deploying GKE Using Public Modules
    1. Technical requirements
    2. Overview
    3. Developing a variable strategy
    4. Provisioning a network using the public module
    5. Provisioning a GKE cluster using the public module
    6. Using workspaces to deploy to development and production environments
    7. Summary
  16. Part 3: Wrapping It Up: Integrating Terraform with Google Cloud
  17. Chapter 9: Developing Terraform Code Efficiently
    1. Technical requirements
    2. VS Code Terraform Extension
      1. Syntax highlighting and validation
      2. Intelligent auto-completion
      3. Code navigation
    3. tflint
    4. Checkov
    5. Terragrunt
    6. Summary
  18. Chapter 10: Google Cloud Integration
    1. Technical requirements
    2. Using Terraform with Cloud Build
    3. Building a service catalog with Terraform solutions
    4. Importing and exporting Terraform resources
      1. Google Cloud export
    5. Summary
    6. Closing thoughts
  19. Index
    1. Why subscribe?
  20. Other Books You May Enjoy
    1. Packt is searching for authors like you
    2. Share Your Thoughts
    3. Download a free PDF copy of this book

Product information

  • Title: Terraform for Google Cloud Essential Guide
  • Author(s): Bernd Nordhausen
  • Release date: January 2023
  • Publisher(s): Packt Publishing
  • ISBN: 9781804619629