Terraform: Up and Running

Book description

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

Publisher resources

View/Submit Errata

Table of contents

  1. Preface
    1. Who Should Read This Book
    2. Why I Wrote This Book
    3. What You Will Find in This Book
    4. What You Won’t Find in This Book
    5. Open Source Code Examples
    6. Using the Code Examples
    7. Conventions Used in This Book
    8. O’Reilly Safari
    9. How to Contact O’Reilly Media
    10. Acknowledgments
  2. 1. Why Terraform
    1. The Rise of DevOps
    2. What Is Infrastructure as Code?
      1. Ad Hoc Scripts
      2. Configuration Management Tools
      3. Server Templating Tools
      4. Server Provisioning Tools
    3. Benefits of Infrastructure as Code
    4. How Terraform Works
    5. How Terraform Compares to Other Infrastructure as Code Tools
      1. Configuration Management Versus Provisioning
      2. Mutable Infrastructure Versus Immutable Infrastructure
      3. Procedural Language Versus Declarative Language
      4. Master Versus Masterless
      5. Agent Versus Agentless
      6. Large Community Versus Small Community
      7. Mature Versus Cutting Edge
    6. Conclusion
  3. 2. Getting Started with Terraform
    1. Set Up Your AWS Account
    2. Install Terraform
    3. Deploy a Single Server
    4. Deploy a Single Web Server
    5. Deploy a Configurable Web Server
    6. Deploy a Cluster of Web Servers
    7. Deploy a Load Balancer
    8. Cleanup
    9. Conclusion
  4. 3. How to Manage Terraform State
    1. What Is Terraform State?
    2. Shared Storage for State Files
    3. Locking State Files
    4. Isolating State Files
    5. File Layout
    6. Read-Only State
    7. Conclusion
  5. 4. How to Create Reusable Infrastructure with Terraform Modules
    1. Module Basics
    2. Module Inputs
    3. Module Outputs
    4. Module Gotchas
      1. File Paths
      2. Inline Blocks
    5. Module Versioning
    6. Conclusion
  6. 5. Terraform Tips and Tricks: Loops, If-Statements, Deployment, and Gotchas
    1. Loops
    2. If-Statements
      1. Simple If-Statements
      2. More Complicated If-Statements
    3. If-Else-Statements
      1. Simple If-Else-Statements
      2. More Complicated If-Else-Statements
    4. Zero-Downtime Deployment
    5. Terraform Gotchas
      1. Count Has Limitations
      2. Zero-Downtime Deployment has Limitations
      3. Valid Plans Can Fail
      4. Refactoring Can Be Tricky
      5. Eventual Consistency Is Consistent…Eventually
    6. Conclusion
  7. 6. How to Use Terraform as a Team
    1. Version Control
      1. A Repository for Modules
      2. A Repository for Live Infrastructure
      3. The Golden Rule of Terraform
    2. Automated Tests
      1. Prepare Your Code
      2. Write the Test Code
      3. Use Multiple Types of Automated Tests
    3. Coding Guidelines
      1. Documentation
      2. File Layout
      3. Style Guide
    4. Workflow
      1. Plan
      2. Staging
      3. Code Review
      4. Production
      5. Some Types of Terraform Changes Can Be Automated
      6. Some Types of Terraform Changes Lead to Conflicts
      7. Larger Teams May Need to Use a Development Pipeline
    5. Conclusion
  8. A. Recommended Reading
    1. Books
    2. Blogs
    3. Talks
    4. Newsletters
    5. Online Forums
  9. Index

Product information

  • Title: Terraform: Up and Running
  • Author(s): Yevgeniy Brikman
  • Release date: March 2017
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781491977088