Terraform: Up and Running: Writing Infrastructure as Code

Terraform: Up and Running: Writing Infrastructure as Code

by Yevgeniy Brikman


$22.49 $24.99 Save 10% Current price is $22.49, Original price is $24.99. You Save 10%.
View All Available Formats & Editions
Eligible for FREE SHIPPING
  • Want it by Thursday, September 27?   Order by 12:00 PM Eastern and choose Expedited Shipping at checkout.
    Same Day shipping in Manhattan. 
    See Details


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

Terraform has emerged as 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, and Azure. This hands-on book is the fastest way to get up and running with Terraform.

Gruntwork co-founder Yevgeniy (Jim) Brikman walks you through dozens of code examples that demonstrate how to use Terraform’s simple, declarative programming language to deploy and manage infrastructure with just a few commands. Whether you’re a novice developer, aspiring DevOps engineer, or veteran sysadmin, this book will take you from Terraform basics to running a full tech stack capable of supporting a massive amount of traffic and a large team of developers.

  • Compare Terraform to other IAC tools, such as Chef, Puppet, Ansible, and Salt Stack
  • Use Terraform to deploy server clusters, load balancers, and databases
  • Learn how Terraform manages the state of your infrastructure and how it impacts file layout, isolation, and locking
  • Create reusable infrastructure with Terraform modules
  • Try out advanced Terraform syntax to implement loops, if-statements, and zero-downtime deployment
  • Use Terraform as a team, including best practices for writing, testing, and versioning Terraform code

Product Details

ISBN-13: 9781491977088
Publisher: O'Reilly Media, Incorporated
Publication date: 04/02/2017
Pages: 206
Sales rank: 421,582
Product dimensions: 7.00(w) x 9.00(h) x 0.60(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

Most Helpful Customer Reviews

See All Customer Reviews