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, considering the management of dependencies.
- It has a multitude of providers.
In this book dedicated to Terraform, we will first discuss the installation of Terraform, the writing of Terraform configurations, how to apply the Terraform workflow using the command-line interface (CLI), and how use Terraform modules.
Once configuration writing and commands in Terraform are understood, we will discuss Terraform’s practical use for building infrastructure with the three leading cloud providers: Azure, AWS, and GCP. We will also explore how to use Terraform for Kubernetes in a chapter dedicated to this topic.
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, Tfsec, 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 to all other Terraform providers.
In this second edition, the chapters have been completely redesigned, with over 50 new recipes and two brand new chapters: one on using Terraform with AWS and GCP, and another on Terraform and Kubernetes.
In writing this cookbook, I wanted to share my experience of real and practical Terraform-based scenarios that I have encountered while working with customers and companies over the years.