Terraform: Up and Running: Writing Infrastructure as Code

Terraform: Up and Running: Writing Infrastructure as Code

by Yevgeniy Brikman
Terraform: Up and Running: Writing Infrastructure as Code

Terraform: Up and Running: Writing Infrastructure as Code

by Yevgeniy Brikman

Paperback(3rd ed.)

$59.99
Choose Expedited Shipping at checkout for delivery by Wednesday, December 7

Overview

Terraform has become a key player in the DevOps world for defining, launching, and managing infrastructure as code (IaC) across a variety of cloud and virtualization platforms, including AWS, Google Cloud, Azure, and more. This hands-on third edition, expanded and thoroughly updated for version 1.0 and beyond, shows you the fastest way to get up and running with Terraform.

Gruntwork cofounder Yevgeniy (Jim) Brikman takes you through code examples that demonstrate Terraform's simple, declarative programming language for deploying and managing infrastructure with a few commands. Veteran sysadmins, DevOps engineers, and novice developers will quickly go from Terraform basics to running a full stack that can support a massive amount of traffic and a large team of developers.

  • Compare Terraform with Chef, Puppet, Ansible, CloudFormation, and Pulumi
  • Deploy servers, load balancers, and databases
  • Create reusable infrastructure with Terraform modules
  • Test your Terraform modules with static analysis, unit tests, and integration tests
  • Configure CI/CD pipelines for both your apps and infrastructure code
  • Use advanced Terraform syntax for loops, conditionals, and zero-downtime deployment
  • Get up to speed on Terraform 0.13 to 1.0 and beyond
  • Work with multiple clouds and providers (including Kubernetes!)


Related collections and offers

Product Details

ISBN-13: 9781098116743
Publisher: O'Reilly Media, Incorporated
Publication date: 10/18/2022
Edition description: 3rd ed.
Pages: 459
Sales rank: 189,641
Product dimensions: 5.90(w) x 8.90(h) x 0.40(d)

About the Author

Yevgeniy (Jim) Brikman loves programming, writing, speaking, traveling, and lifting heavy things. He is the co-founder of Gruntwork, a company that helps startups get up and running on AWS with DevOps best practices and world-class infrastructure. He's also the author of "Hello, Startup: A Programmer's Guide to Building Products, Technologies, and Teams," a book published by O'Reilly Media that has a 4.9/5.0 rating on Amazon and 4.5/5.0 rating on GoodReads. Previously, he worked as a software engineer at LinkedIn, TripAdvisor, Cisco Systems, and Thomson Financial and got his BS and Masters at Cornell University. For more info, check out ybrikman.com.

Table of Contents

Preface ix

1 Why Terraform 1

The Rise of DevOps 1

What Is Infrastructure as Code? 3

Ad Hoc Scripts 4

Configuration Management Tools 5

Server Templating Tools 7

Server Provisioning Tools 11

Benefits of Infrastructure as Code 13

How Terraform Works 15

How Terraform Compares to Other Infrastructure as Code Tools 17

Configuration Management Versus Provisioning 18

Mutable Infrastructure Versus Immutable Infrastructure 19

Procedural Language Versus Declarative Language 19

Master Versus Masterless 22

Agent Versus Agentless 23

Large Community Versus Small Community 25

Mature Versus Cutting Edge 27

Conclusion 27

2 Getting Started with Terraform 29

Set Up Your AWS Account 30

Install Terraform 33

Deploy a Single Server 34

Deploy a Single Web Server 39

Deploy a Configurable Web Server 45

Deploy a Cluster of Web Servers 49

Deploy a Load Balancer 52

Cleanup 58

Conclusion 58

3 How to Manage Terraform State 59

What Is Terraform State? 60

Shared Storage for State Files 61

Locking State Files 66

Isolating State Files 68

File Layout 70

Read-Only State 73

Conclusion 81

4 How to Create Reusable Infrastructure with Terraform Modules 83

Module Basics 88

Module Inputs 90

Module Outputs 94

Module Gotchas 96

File Paths 96

Inline Blocks 96

Module Versioning 99

Conclusion 104

5 Terraform Tips and Tricks: Loops, If-Statements, Deployment, and Gotchas 107

Loops 108

If-Statements 113

Simple If-Statements 113

More Complicated If-Statements 115

If-Else-Statements 117

Simple If-Else-Statements 118

More Complicated If-Else-Statements 119

Zero-Downtime Deployment 123

Terraform Gotchas 134

Count Has Limitations 134

Zero-Downtime Deployment has Limitations 136

Valid Plans Can Fail 137

Refactoring Can Be Tricky 139

Eventual Consistency Is Consistent…Eventually 141

Conclusion 142

6 How to Use Terraform as a Team 143

Version Control 144

A Repository for Modules 144

A Repository for Live Infrastructure 144

The Golden Rule of Terraform 145

Automated Tests 147

Prepare Your Code 147

Write the Test Code 151

Use Multiple Types of Automated Tests 153

Coding Guidelines 154

Documentation 154

File Layout 155

Style Guide 156

Workflow 157

Plan 157

Staging 157

Code Review 158

Production 159

Some Types of Terraform Changes Can Be Automated 159

Some Types of Terraform Changes Lead to Conflicts 160

Larger Teams May Need to Use a Development Pipeline 163

Conclusion 169

A Recommended Reading 171

Index 175

Customer Reviews