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.