Book Image

Terraform Cookbook

By : Mikael Krief
Book Image

Terraform Cookbook

By: Mikael Krief

Overview of this book

HashiCorp Configuration Language (HCL) has changed how we define and provision a data center infrastructure with the launch of Terraform—one of the most popular and powerful products for building Infrastructure as Code. This practical guide will show you how to leverage HashiCorp's Terraform tool to manage a complex infrastructure with ease. Starting with recipes for setting up the environment, this book will gradually guide you in configuring, provisioning, collaborating, and building a multi-environment architecture. Unlike other books, you’ll also be able to explore recipes with real-world examples to provision your Azure infrastructure with Terraform. Once you’ve covered topics such as Azure Template, Azure CLI, Terraform configuration, and Terragrunt, you’ll delve into manual and automated testing with Terraform configurations. The next set of chapters will show you how to manage a balanced and efficient infrastructure and create reusable infrastructure with Terraform modules. Finally, you’ll explore the latest DevOps trends such as continuous integration and continuous delivery (CI/CD) and zero-downtime deployments. By the end of this book, you’ll have developed the skills you need to get the most value out of Terraform and manage your infrastructure effectively.
Table of Contents (10 chapters)

What this book covers

Chapter 1, Setting Up the Terraform Environment, details the different ways of installing Terraform manually, with scripts, or by using a Docker container, and it also details the Terraform migration configuration process.

Chapter 2, Writing Terraform Configuration, concerns the writing of Terraform configurations for a provider, variables, outputs, external data, built-in functions, condition expressions, file manipulation, and the execution of local programs with Terraform.

Chapter 3, Building Dynamic Environments with Terraform, discusses building dynamic environments with Terraform by going further with Terraform configuration writing using loops, maps, and collections.

Chapter 4, Using the Terraform CLI, explains the use of Terraform's CLI to clean code, destroy resources provisioned by Terraform, use workspaces, import existing resources, generate dependency graphs, and debug the execution of Terraform.

Chapter 5, Sharing Terraform Configuration with Modules, covers the creation, use, and sharing of Terraform modules. It also shows testing module practices and the implementation of CI/CD pipelines for Terraform modules.

Chapter 6, Provisioning Azure Infrastructure with Terraform, illustrates the use of Terraform in a practical scenario of the cloud provider Azure. It covers topics such as authentication, remote backends, ARM templates, Azure CLI execution, and Terraform configuration generation for an existing infrastructure.

Chapter 7, Deep Diving into Terraform, discusses topics that go further with Terraform, such as the execution of Terraform configuration tests, zero-downtime deployment, Terraform wrappers with Terragrunt, and the implementation of CI/CD pipelines to execute Terraform configurations.

Chapter 8, Using Terraform Cloud to Improve Collaboration, explains the use of Terraform Cloud to run Terraform in a team with the sharing of Terraform modules in a private registry, the use of remote backends for Terraform state, running Terraform remotely, and writing compliance tests with Sentinel.