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)

Writing Terraform configuration in VS Code

Writing a Terraform configuration file does not require a special code editor. However, popular code editors have adapted and now offer plugins that simplify writing such a file.

In this recipe, we will focus on Visual Studio Code, which has the following benefits:

  • It's cross-platform, which means it can be installed on Windows, Linux, and macOS.
  • It's free of charge.
  • It has a multitude of extensions that cover all the needs of developers on a daily basis.

In this recipe, we will learn how to configure Visual Studio Code so that we can write the Terraform configuration. We'll also see how much faster it is to write code in this way.

Getting ready

For this recipe, you need to have Visual Studio Code installed on your local machine. You can install it by going to https://code.visualstudio.com/.

How to do it…

To use Visual Studio Code with Terraform, we need to install the respective extension and configure it.

To install...