Terraform Cookbook
eBook - ePub

Terraform Cookbook

Mikael Krief

Compartir libro
  1. 366 páginas
  2. English
  3. ePUB (apto para móviles)
  4. Disponible en iOS y Android
eBook - ePub

Terraform Cookbook

Mikael Krief

Detalles del libro
Vista previa del libro
Índice
Citas

Información del libro

Discover how to manage and scale your infrastructure using Infrastructure as Code (IaC) with Terraform

Key Features

  • Get up and running with the latest version of Terraform, v0.13
  • Design and manage infrastructure that can be shared, tested, modified, provisioned, and deployed
  • Work through practical recipes to achieve zero-downtime deployment and scale your infrastructure effectively

Book Description

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.

What you will learn

  • Understand how to install Terraform for local development
  • Get to grips with writing Terraform configuration for infrastructure provisioning
  • Use Terraform for advanced infrastructure use cases
  • Understand how to write and use Terraform modules
  • Discover how to use Terraform for Azure infrastructure provisioning
  • Become well-versed in testing Terraform configuration
  • Execute Terraform configuration in CI/CD pipelines
  • Explore how to use Terraform Cloud

Who this book is for

This book is for developers, operators, and DevOps engineers looking to improve their workflow and use Infrastructure as Code. Experience with Microsoft Azure, Jenkins, shell scripting, and DevOps practices is required to get the most out of this Terraform book.

]]>

Preguntas frecuentes

¿Cómo cancelo mi suscripción?
Simplemente, dirígete a la sección ajustes de la cuenta y haz clic en «Cancelar suscripción». Así de sencillo. Después de cancelar tu suscripción, esta permanecerá activa el tiempo restante que hayas pagado. Obtén más información aquí.
¿Cómo descargo los libros?
Por el momento, todos nuestros libros ePub adaptables a dispositivos móviles se pueden descargar a través de la aplicación. La mayor parte de nuestros PDF también se puede descargar y ya estamos trabajando para que el resto también sea descargable. Obtén más información aquí.
¿En qué se diferencian los planes de precios?
Ambos planes te permiten acceder por completo a la biblioteca y a todas las funciones de Perlego. Las únicas diferencias son el precio y el período de suscripción: con el plan anual ahorrarás en torno a un 30 % en comparación con 12 meses de un plan mensual.
¿Qué es Perlego?
Somos un servicio de suscripción de libros de texto en línea que te permite acceder a toda una biblioteca en línea por menos de lo que cuesta un libro al mes. Con más de un millón de libros sobre más de 1000 categorías, ¡tenemos todo lo que necesitas! Obtén más información aquí.
¿Perlego ofrece la función de texto a voz?
Busca el símbolo de lectura en voz alta en tu próximo libro para ver si puedes escucharlo. La herramienta de lectura en voz alta lee el texto en voz alta por ti, resaltando el texto a medida que se lee. Puedes pausarla, acelerarla y ralentizarla. Obtén más información aquí.
¿Es Terraform Cookbook un PDF/ePUB en línea?
Sí, puedes acceder a Terraform Cookbook de Mikael Krief en formato PDF o ePUB, así como a otros libros populares de Computer Science y Software Development. Tenemos más de un millón de libros disponibles en nuestro catálogo para que explores.

Información

Año
2020
ISBN
9781800209626
Sharing Terraform Configuration with Modules
The real challenge for developers and software factories in recent years has been to stop writing the portions of code that are repeated between applications and even between teams. Hence the emergence of language, framework, and software packages that are easily reusable in several applications and that can be shared between several teams (such as NuGet, NPM, Bower, PyPI, RubyGems, and many others). In Infrastructure as Code (IaC) in general, we also encounter the same problems of code structure, its homogenization, and its sharing in the company.
We learned in the Provisioning infrastructure in multiple environments recipe of Chapter 2, Writing Terraform Configuration, some topologies of the structure of the Terraform configuration, that gave us a partial answer to the question of how to structure a Terraform configuration well. But that doesn't stop there—Terraform also allows you to create modules with which you can share Terraform configuration between several applications and several teams.
In this chapter, we will study the main stages of the modules, which are: the creation, use, and publishing of Terraform modules. We will learn about the creation of a Terraform module and its local use, as well as the rapid bootstrapping of the code of a module. We will also study the use of Terraform modules using the public registry or a Git repository. Finally, we will study how to test a module as well as an example of a CI/CD pipeline of a Terraform module in Azure Pipelines and GitHub Actions.
In this chapter, we cover the following recipes:
  • Creating a Terraform module and using it locally
  • Using modules from the public registry
  • Sharing a Terraform module using GitHub
  • Using another file inside a custom module
  • Using the Terraform module generator
  • Generating module documentation
  • Using a private Git repository for sharing Terraform modules
  • Applying a Terrafile pattern for using modules
  • Testing Terraform module code with Terratest
  • Building CI/CD for Terraform modules in Azure Pipelines
  • Building a workflow for Terraform modules using GitHub Actions

Technical requirements

In this chapter, for some recipes, we will need certain prerequisites, which are as follows:
  • To have Node.js and NPM installed on your computer: The download website is here: https://nodejs.org/en/.
  • To have a GitHub account: If you don't have one, the creation of the account is free and can be done here: https://github.com/.
  • To have an Azure DevOps organization: You can create one with a Live or GitHub account here: https://azure.microsoft.com/en-in/services/devops/.
  • To have a basic knowledge of Git commands and workflow: The documentation is available here: https://git-scm.com/doc.
  • To know about Docker: The documentation is here: https://docs.docker.com/.
  • To install Golang on our workstation: The documentation is here: https://golang.org/doc/install. We will see the main steps of its installation in the Testing a Terraform module using Terratest recipe.
The complete source code for this chapter is available on GitHub at https://github.com/PacktPublishing/Terraform-Cookbook/tree/master/CHAP05.
Check out the following video to see the Code in Action: https://bit.ly/3ibKgH2

Creating a Terraform module and using it locally

A Terraform module is a Terraform configuration that contains one or more Terraform resource. Once created, this module can be used in several Terraform configuration files either locally or even remotely.
In this recipe, we will look at the basics of a Terraform module with the steps involved in creating a module and using it locally.

Getting ready

To start this recipe, we will use the Terraform configuration that we have already written in the Provisioning infrastructure in multiple environments recipe in Chapter 2, Writing Terraform Configuration, and whose sources can be found at https://github.com/PacktPublishing/Terraform-Cookbook/tree/master/CHAP05/sample-app.
The module we will create in this recipe will be in charge of providing a Service Plan, one App Service, and an Application Insights resource in Azure. Its source code is available here: https://github.com/PacktPublishing/Terraform-Cookbook/tree/master/CHAP05/moduledemo/Modules/webapp. Then, we will write a Terraform configuration that uses this module and the code is here: https://github.com/PacktPublishing/Terraform-Cookbook/tree/master/CHAP05/moduledemo/MyApp.

How to do it…

To create the module, perform the following steps:
  1. In a new folder called moduledemo, create the Modules and webapp folders.
  1. In the webapp folder, create a new variables.tf file with the following code:
variable "resource_group_name" {
description = "Resource group name"
}

variable "location" {
description = "Location of Azure resource"
default = "West Europe"
}

variable "service_plan_name" {
description = "Service plan name"
}

variable "app_name" {
description = "Name of application"
}
  1. Then, create the main.tf file with the following code:
resource "azurerm_app_service_plan" "plan-app" {
name = var.service_plan_name
...

Índice