O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Terraform: Up & Running, 2nd Edition

Book Description

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 many more. Expanded and thoroughly updated, this hands-on second edition shows you the fastest way to get up and running with Terraform 0.12.

Gruntwork cofounder Yevgeniy (Jim) Brikman walks you through dozens of code examples that demonstrate how to use 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.

  • Get up to speed on all changes from Terraform 0.9 through 0.12, including backends, workspaces, first-class expressions, and much more
  • Explore two new chapters on producing and testing Terraform code
  • Compare Terraform to Chef, Puppet, Ansible, and Salt Stack
  • Deploy server clusters, load balancers, and databases
  • Use Terraform to manage the state of your infrastructure
  • Create reusable infrastructure with Terraform modules
  • Use advanced Terraform syntax to achieve zero-downtime deployment

Table of Contents

  1. 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
  2. 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
  3. 3. How to Manage Terraform State
    1. What Is Terraform State?
    2. Shared Storage for State Files
    3. Some limitations with Terraform’s backends
    4. Isolating State Files
      1. Isolation via workspaces
      2. Isolation via file layout
    5. The terraform_remote_state data source
    6. Conclusion
  4. 4. How to Create Reusable Infrastructure with Terraform Modules
    1. Module Basics
    2. Module Inputs
    3. Module Locals
    4. Module Outputs
    5. Module Gotchas
      1. File Paths
      2. Inline Blocks
    6. Module Versioning
    7. Conclusion
  5. 5. Terraform Tips and Tricks: Loops, If-Statements, Deployment, and Gotchas
    1. Loops
      1. Loops with the count parameter
      2. Loops with for_each expressions
      3. Loops with for expressions
      4. Loops with the for string directive
    2. Conditionals
      1. Conditionals with the count parameter
      2. Conditionals with for_each and for expressions
      3. Conditionals with the if string directive
    3. Zero-Downtime Deployment
    4. 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
    5. Conclusion
  6. 6. Production-grade Terraform code
    1. Why it takes so long to build production-grade infrastructure
    2. The production-grade infrastructure checklist
    3. Production-grade infrastructure modules
      1. Small modules
      2. Composable modules
      3. Testable modules
      4. Releasable modules
      5. Beyond Terraform modules
    4. Conclusion
  7. 7. How to test Terraform code
    1. Manual tests
      1. Manual testing basics
      2. Cleaning up after tests
    2. Automated tests
      1. Unit tests
      2. Integration tests
      3. End-to-end tests
      4. Other testing approaches
    3. Conclusion