Terraform Cookbook
eBook - ePub

Terraform Cookbook

Mikael Krief

Buch teilen
  1. 366 Seiten
  2. English
  3. ePUB (handyfreundlich)
  4. Über iOS und Android verfügbar
eBook - ePub

Terraform Cookbook

Mikael Krief

Angaben zum Buch
Buchvorschau
Inhaltsverzeichnis
Quellenangaben

Über dieses Buch

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.

]]>

Häufig gestellte Fragen

Wie kann ich mein Abo kündigen?
Gehe einfach zum Kontobereich in den Einstellungen und klicke auf „Abo kündigen“ – ganz einfach. Nachdem du gekündigt hast, bleibt deine Mitgliedschaft für den verbleibenden Abozeitraum, den du bereits bezahlt hast, aktiv. Mehr Informationen hier.
(Wie) Kann ich Bücher herunterladen?
Derzeit stehen all unsere auf Mobilgeräte reagierenden ePub-Bücher zum Download über die App zur Verfügung. Die meisten unserer PDFs stehen ebenfalls zum Download bereit; wir arbeiten daran, auch die übrigen PDFs zum Download anzubieten, bei denen dies aktuell noch nicht möglich ist. Weitere Informationen hier.
Welcher Unterschied besteht bei den Preisen zwischen den Aboplänen?
Mit beiden Aboplänen erhältst du vollen Zugang zur Bibliothek und allen Funktionen von Perlego. Die einzigen Unterschiede bestehen im Preis und dem Abozeitraum: Mit dem Jahresabo sparst du auf 12 Monate gerechnet im Vergleich zum Monatsabo rund 30 %.
Was ist Perlego?
Wir sind ein Online-Abodienst für Lehrbücher, bei dem du für weniger als den Preis eines einzelnen Buches pro Monat Zugang zu einer ganzen Online-Bibliothek erhältst. Mit über 1 Million Büchern zu über 1.000 verschiedenen Themen haben wir bestimmt alles, was du brauchst! Weitere Informationen hier.
Unterstützt Perlego Text-zu-Sprache?
Achte auf das Symbol zum Vorlesen in deinem nächsten Buch, um zu sehen, ob du es dir auch anhören kannst. Bei diesem Tool wird dir Text laut vorgelesen, wobei der Text beim Vorlesen auch grafisch hervorgehoben wird. Du kannst das Vorlesen jederzeit anhalten, beschleunigen und verlangsamen. Weitere Informationen hier.
Ist Terraform Cookbook als Online-PDF/ePub verfügbar?
Ja, du hast Zugang zu Terraform Cookbook von Mikael Krief im PDF- und/oder ePub-Format sowie zu anderen beliebten Büchern aus Computer Science & Software Development. Aus unserem Katalog stehen dir über 1 Million Bücher zur Verfügung.

Information

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
...

Inhaltsverzeichnis