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)
Preface

Infrastructure as Code, more commonly known as IaC, is a practice that is a pillar of DevOps culture. IaC entails writing your desired architecture configuration in code. Among other advantages, IaC allows the automation of infrastructure deployments, which reduces or eliminates the need for manual intervention, and thus the risk of configuration errors, and the need to create templates and standardize infrastructure with modular and scalable code.

Among all the DevOps tools, there are many that allow IaC. One of them is Terraform, from HashiCorp, which is very popular today because, in addition to being open source and multi-platform, it has the following advantages:

  • It allows you to preview the changes that will be applied to your infrastructure.
  • It allows the parallelization of operations, taking into account the management of dependencies.
  • It has a multitude of providers.

In this book dedicated to Terraform, we will first discuss the installation of Terraform for local development, the writing of Terraform configurations, and the construction of several environments in a dynamic way.

Then, we will learn how to use the Terraform command-line interface (CLI) and how to share and use Terraform modules.

Once configuration writing and commands in Terraform are understood, we will discuss Terraform's practical use for building infrastructure in one of the leading cloud providers, Azure.

Finally, we will finish this book by looking at advanced uses of Terraform, including Terraform testing, integrating Terraform into a continuous integration/continuous deployment (CI/CD) pipeline, and using Terraform Cloud, which is Terraform's collaboration platform for teams and companies.

This book will guide you through several recipes on best practices for writing Terraform configurations and commands, and it will also cover recipes on Terraform's integration with other tools, such as Terragrunt, kitchen-terraform, and Azure Pipelines.

Most of the Terraform configurations described in this book are based on the Azure provider for illustration, but you can apply these recipes for all other Terraform providers.

In writing this book, which is in a cookbook format, I wanted to share my experience of real and practical Terraform-based scenarios that I have been able to acquire by working with customers and companies for several years.