From First Configuration to Production Infrastructure at Scale
Chapter 1: The Infrastructure Problem and the Code Solution
- The Chaos of Manual Infrastructure
- What Infrastructure as Code Means
- Declarative Versus Imperative Approaches
- How Terraform Fits Into the IaC Landscape
- Core Principles That Guide Terraform Design
Chapter 2: Getting Started with Terraform
- Installing Terraform and Verifying Your Setup
- Understanding the Terraform Project Layout
- Writing Your First Configuration File
- The Initialization Step and Provider Plugins
- Planning Changes Before Applying Them
- Creating, Updating, and Destroying Resources
- Reading Terraform Output
Chapter 3: HCL Language Fundamentals
- Blocks, Arguments, and Identifiers
- Value Types in Terraform
- Collections: Lists, Maps, Sets, and Objects
- Expressions and Operators
- String Templates and Interpolation
- Comments and Documentation Style
- Common Syntax Mistakes and How to Avoid Them
Chapter 4: Resources and Providers, The Building Blocks
- What Providers Are and How They Work
- Configuring Providers With Version Constraints
- Defining Resources and Understanding Their Arguments
- Resource Attributes Versus Arguments
- Data Sources for Reading External Information
- Provider Aliases and Multiple Configurations
- When to Use a Separate Provider Block
Chapter 5: Variables, Local Values, and Outputs
- Input Variables: Types, Defaults, and Validation
- Variable Definitions in Separate Files
- Passing Variables at the Command Line and Via Environment
- Local Values for Derived and Reused Expressions
- Outputs: Exposing Information From Configurations
- Sensitive Outputs and When to Mark Them
Chapter 6: State, How Terraform Tracks Reality
- What State Is and Why It Matters
- The State File Structure and Contents
- How Terraform Uses State During Planning
- Local Versus Remote State Storage
- Inspecting State With CLI Commands
- State as a Source of Truth, And a Liability
- Common State Pitfalls and How to Avoid Them
Chapter 7: Modules, Building Reusable Infrastructure
- What a Module Is and Why You Need Them
- Root Modules Versus Child Modules
- Defining Module Inputs and Outputs
- Calling Modules and Passing Configuration
- For Each With Modules for Repeated Instances
- Using Published Modules From the Registry
- Designing Well-Factored Modules
Chapter 8: Dependencies, Order of Operations, and Lifecycle Rules
- Implicit Dependencies Through Attribute References
- Explicit Dependencies With the Depends On Argument
- Understanding the Dependency Graph
- Creating Before Destroying: Create Before Destroy
- Preventing Accidental Deletion With Prevent Destroy
- Ignoring Unwanted Changes With Ignore Changes
- When to Use Provisioners, And When Not To
Chapter 9: Advanced Expressions, Functions, and Dynamic Blocks
- Conditional Expressions and Null Handling
- Splat Expressions and For Expressions
- Built-In Functions: Categories and Common Uses
- Type Conversion Functions and When They Are Needed
- Dynamic Blocks for Repeated Nested Configuration
- Combining Techniques in Realistic Examples
Chapter 10: Remote Backends, State Locking, and Team Collaboration
- Why Local State Does Not Scale to Teams
- Configuring Remote Backends: S3, GCS, Azure Blob, Terraform Cloud
- State Locking Mechanisms and How They Work
- Backend Migration From Local to Remote
- Encrypting State at Rest
- Managing Access to State Files
Chapter 11: Environment Management and Workspaces
- The Multi-Environment Problem
- Using Terraform Workspaces
- Workspace-Aware Variables and Resources
- Separate State Files Per Environment: An Alternative
- Choosing Between Workspaces and Directory-Based Environments
- Tagging and Naming Strategies Across Environments
Chapter 12: Security, Secrets, and Access Control
- Handling Sensitive Variables and Values
- Storing Secrets Securely: Vault, Parameter Store, Key Vault
- Authenticating Providers Without Hardcoded Credentials
- Restricting State File Access
- Scanning Configurations for Security Issues
- Least Privilege Principles for Terraform Service Accounts
Chapter 13: Testing, Validation, and Quality Assurance
- Formatting and Linting With Fmt and Tflint
- Validating Configurations Before Planning
- Policy as Code With Sentinel and OPA
- Writing Tests for Terraform Modules
- Pre-Commit Hooks and Automated Checks
- Reviewing Plans in Pull Requests
Chapter 14: CI/CD Integration and Automation
- The Basic CI/CD Pipeline for Infrastructure
- Automated Planning in Pull Requests
- Approval Gates and Run Triggers
- Applying Changes Safely in Production Pipelines
- Handling Plan Failures and Rollback Strategies
- Example Pipelines With GitHub Actions and GitLab CI
Chapter 15: Terraform Cloud and Enterprise Features
- Terraform Cloud Versus Self-Managed Workflows
- Remote Execution and State Management in the Cloud
- Team Access Control and Run Policies
- Cost Estimation and Budget Alerts
- Terraform Enterprise for Large Organizations
- When to Use Managed Services Versus DIY
Chapter 16: Refactoring, Importing, Moving, and Disaster Recovery
- Importing Existing Resources Into Terraform State
- Moving Resources Between Modules With State Commands
- Refactoring Configurations Without Disrupting Infrastructure
- Upgrading Terraform Versions Safely
- Recovering From Accidental State Deletion
- Disaster Recovery Procedures for State and Infrastructure
Chapter 17: Production Patterns and Complete Architectures
- Repository Organization for Large Teams
- Multi-Account and Multi-Region Patterns
- Networking as a Shared Foundation Layer
- Security Boundaries and Isolation Strategies
- A Complete Production Example: End-to-End Architecture
- Naming Conventions, Version Constraints, and Team Standards
Conclusion: The Path to Terraform Mastery
- What Mastery Really Means
- The Ongoing Challenges of Infrastructure as Code
- Where to Go From Here