Book description
Cloud services and SaaS software permeate every company's IT landscape, requiring a shift from manually provisioned services to a more structured approach, with codification at its core. Terraform provides tools to manage the lifecycle of your IT landscape across thousands of different cloud providers and SaaS platforms.
By defining your infrastructure as code you can safely and predictably make changes, modularize crucial building blocks, and create reusable service components. Each recipe in this cookbook addresses a specific problem and prefaces the solution with detailed insights into the "how" and "why".
If you're just starting with Terraform and codified infrastructure, this book will help you create a solid foundation, on which you can build for years to come. If you're an advanced user, this guide will help you reaffirm your knowledge and take it to the next level, as you challenge yourself with more complex infrastructure, spread across multiple providers.
Recipes include:
- Strategies on how to use Terraform with Version Control Systems
- Validation and testing patterns for Terraform-managed infrastructure
- Methods for importing pre-existing resources
- Transforming infrastructure services into reusable components
- Integrating Terraform with other HashiCorp tools
- Deploying Containerized Workloads
Publisher resources
Table of contents
- Preface
-
1. Getting Started with Terraform
- 1.1. When to Use Terraform
- 1.2. When Not to Use Terraform
- 1.3. Installing and Configuring Terraform
- 1.4. Understanding Terraform Providers
- 1.5. Understanding Terraform Modules
- 1.6. Modifying Terraform State with terraform console
- 1.7. Using HashiCorp Cloud Platform Terraform
- 1.8. Using Terraform with Visual Studio Code
- 1.9. Managing Terraform Provider Version Constraints
- 1.10. Strategies for Deploying Version-Controlled Terraform Code Repositories
- 1.11. Deploying a Docker Container with Terraform
- 1.12. Upgrading Terraform: From 0.x to 1.x and Beyond
- 1.13. Using Terraform Variables
- 1.14. Consistent Code for a Consistent Experience
-
2. Terraform Basics
- 2.1. Formatting and Validating Terraform Code
- 2.2. Rapid Experimentation with terraform console
- 2.3. Improving Code Quality with TFLint
- 2.4. Improving Code Quality with TFSec
- 2.5. Validating Code with Preconditions and Postconditions
- 2.6. Validating Code with Open Policy Agent
- 2.7. Documenting Code with terraform-docs
- 2.8. Automating Code Validation with GitHub Actions
- 2.9. Using Dependabot for Provider Version Updates
- 2.10. Using GitHub Codespaces and DevContainers
- 2.11. Limiting Blast Radius with Terraform
-
3. Terraform Syntax Patterns
- 3.1. Cleaning User Inputs with trimspace
- 3.2. Removing Prefixes and Suffixes
- 3.3. Working with Regular Expressions
- 3.4. Advanced String Manipulation
- 3.5. Working with Case-Sensitive Strings Using title, upper, and lower
- 3.6. Alphabetically Sorting Lists
- 3.7. Creating Subnets from a CIDR Block
- 3.8. Interacting with the Local Filesystem
- 3.9. Rendering Templates
- 3.10. Validating Input Strings
- 3.11. Optimistically Retrieving Data Using can and try
- 3.12. Sequentially Processing Input Data
- 3.13. Good Error Messages for Bad Input
- 3.14. Consuming Data Across Terraform States
-
4. Terraform Modules and Providers
- 4.1. Using Public Modules to Create an EKS Cluster
- 4.2. Linting Terraform with GitHub Actions
- 4.3. Authentication for Terraform Providers
- 4.4. Authentication for Private Modules
- 4.5. Creating a Terraform Module
- 4.6. Managing GitHub Secrets with Terraform
- 4.7. Managing GitHub Repositories with Terraform
- 4.8. Dynamic Configuration with Consul KV
- 4.9. Service-Health-Aware Provider Configuration
- 4.10. Consuming Terraform State with Providers
- 4.11. Using Multiple, Identical Providers
-
5. Container Management with Terraform
- 5.1. Using Local Versus Remote Docker Images
- 5.2. Distinguishing Between Cluster Deployment and Cluster Configuration
- 5.3. Authorizing Terraform for Cluster Operations
- 5.4. Scheduling Containers on Kubernetes with YAML
- 5.5. Scheduling Containers on Kubernetes with HCL
- 5.6. Transmuting Kubernetes YAML into HCL using k2tf
- 5.7. Adjusting Annotations for Kubernetes Deployments
- 5.8. Adjusting Configuration for Kubernetes Deployments
- 5.9. Applying Kubernetes NetworkPolicies with Terraform
- 5.10. Deploying Containers with Helm
- 5.11. Enabling Monitoring for Kubernetes Deployments Using Helm
- 5.12. Scheduling Containers on HashiCorp Nomad
-
6. HCP Terraform and Terraform Enterprise
- 6.1. Setting Up HCP Terraform
- 6.2. Integrating HCP Terraform with VCS
- 6.3. Consuming Terraform State with HCP Terraform
- 6.4. Using HCP Terraform with GitHub Actions
- 6.5. Collaborative Workflows with HCP Terraform
- 6.6. Troubleshooting HCP Terraform and Terraform Enterprise
- 6.7. Enforcing Policy as Code
- 6.8. Managing Costs with HCP Terraform
- 6.9. Utilizing Remote Operations for Large-Scale Deployments
- 6.10. Advanced State Management and Recovery
-
7. Consuming and Managing Secrets with Terraform
- 7.1. Dealing with Sensitive Data in Terraform
- 7.2. Retrieving Key-Values from HashiCorp Vault
- 7.3. Managing Kubernetes Secrets with Kubernetes-Native Functions
- 7.4. Managing Kubernetes Secrets with Vault and Terraform
- 7.5. Storing Secrets as Environment Variables
- 7.6. Auditing and Rotating Secrets
- 7.7. Managing Secrets with Terraform and Password Managers
- 7.8. Compliance and Governance with Terraform Secrets
- 7.9. Dynamic Secrets with HashiCorp Vault
- 7.10. Securing Secret Injection in CI/CD Pipelines
-
8. Configuration Management with Terraform
- 8.1. Writing Shell Scripts with Terraform
- 8.2. Writing Ansible Configuration with Terraform
- 8.3. Dynamic Configuration with Consul Key-Values
- 8.4. Consuming Data from HTTP Interfaces
- 8.5. Applying Conditional Logic in Terraform
- 8.6. Importing Existing Infrastructure into Terraform
- 8.7. Leveraging Terraform Workspaces
- 8.8. Utilizing Terraform Templates
- 8.9. Managing Dependencies Between Terraform Resources
- 8.10. Using Terraform for Blue-Green Deployments
-
9. Advanced Terraform Techniques
- 9.1. Writing Configuration Files with Terraform
- 9.2. Writing Cloud-Init Configuration
- 9.3. Implementing Terraform Modules in CI/CD Pipelines
- 9.4. Advanced State Management in Terraform
- 9.5. Terraform and Multicloud Strategies
- 9.6. Terraform for Scalable Architectures
- 9.7. Terraform Custom Provider Development
- 9.8. Integrating Terraform with Monitoring Tools
- 9.9. Managing Security and Compliance with Terraform
- 9.10. Advanced Debugging Techniques in Terraform
-
10. Real-World Use Cases
- 10.1. Managing Multiple Environments with Terraform Workspaces
- 10.2. Deploying a Highly Available Web Application Across Regions
- 10.3. Provisioning a Scalable Kubernetes Cluster on AWS EKS
- 10.4. Implementing Blue-Green Deployments with Terraform
- 10.5. Automating Database Migrations with Terraform and AWS RDS
- 10.6. Deploying a Serverless Application on AWS Lambda and API Gateway
- 10.7. Implementing Infrastructure as Code for GitOps Workflows
- 10.8. Optimizing Costs with Terraform and Spot Instances
- 10.9. Deploying a Multicloud Monitoring Solution with Terraform
- 10.10. Automating Disaster Recovery with Terraform and AWS
- Index
- About the Authors
Product information
- Title: Terraform Cookbook
- Author(s):
- Release date: October 2024
- Publisher(s): O'Reilly Media, Inc.
- ISBN: 9781098108465
You might also like
book
Terraform Cookbook
Discover how to manage and scale your infrastructure using Infrastructure as Code (IaC) with Terraform Key …
book
Terraform Cookbook - Second Edition
Explore how to provision, manage, and scale your infrastructure using Infrastructure as Code (IaC) with Terraform …
book
Kubernetes Cookbook
Kubernetes is becoming the de-facto standard for container orchestration and distributed applications management across a microservices …
book
Terraform: Up & Running, 2nd Edition
Terraform has become a key player in the DevOps world for defining, launching, and managing infrastructure …