Terraform Cookbook: Provision, run, and scale Azure, AWS, and GCP architecture, 2nd Edition

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

HashiCorp Configuration Language (HCL) has changed how we define and provision data center infrastructure with the launch of Terraform―a top-tier product for building Infrastructure as Code (IaC). Terraform Cookbook shows you how to leverage Terraform to manage complex infrastructure with ease. This new edition has been updated to include real-world examples for provisioning Azure, AWS, and GCP infrastructure with Terraform. You'll delve into manual and automated testing with Terraform configurations, creating and managing a balanced, efficient, reusable infrastructure with Terraform modules. You’ll learn how to automate the deployment of Terraform configuration with continuous integration and continuous delivery (CI/CD). Besides, several new chapters have been added that describes the use of Terraform for Docker and Kubernetes, examine advanced topics on GitOps practices, and explain how to test Terraform configurations using different tools to check code and security compliance. The final chapter covers troubleshooting common Terraform issues and provides solutions for frequently encountered errors. By the end of this book, you'll have developed the skills needed to get the most value out of Terraform and to effectively manage your infrastructure.

Author(s): Mikael Krief
Edition: 2
Publisher: Packt
Year: 2023

Language: English
Pages: 805

Preface
Who this book is for
What this book covers
To get the most out of this book
Get in touch
Setting Up the Terraform Environment
Technical requirements
Overviewing Terraform best practices
Downloading and installing Terraform on Windows manually
Getting ready
How to do it…
How it works…
Installing Terraform using Chocolatey on Windows
Getting ready
How to do it…
How it works…
There’s more…
See also
Installing Terraform on Linux using the APT package manager
Getting ready
How to do it…
How it works…
See also
Installing Terraform using a script on Linux
Getting ready
How to do it…
How it works…
There’s more…
See also
Executing Terraform in a Docker container
Getting ready
How to do it…
How it works…
There’s more…
See also
Switching between multiple Terraform versions
Getting ready
How to do it…
How it works…
There’s more…
See also
Upgrading Terraform providers
Getting ready
How to do it…
How it works…
There’s more…
See also
Writing Terraform Configurations
Technical requirements
Configuring Terraform and the provider version to use
Getting ready
How to do it…
How it works…
There’s more…
See also
Adding alias to a provider to use multiple instances of the same provider
Getting ready
How to do it…
How it works…
See also
Manipulating variables
Getting ready
How to do it…
How it works…
There’s more…
See also
Keeping sensitive variables safe
Getting ready
How to do it…
How it works…
There’s more…
See also
Using local variables for custom functions
Getting ready
How to do it…
How it works…
There’s more…
See also
Using outputs to expose Terraform provisioned data
Getting ready
How to do it…
How it works…
There’s more…
See also
Calling Terraform’s built-in functions
Getting ready
How to do it…
How it works…
See also
Using YAML files in Terraform configuration
Getting ready
How to do it…
How it works…
There’s more…
See also
Writing conditional expressions
Getting ready
How to do it…
How it works…
There’s more…
See also
Generating passwords with Terraform
Getting ready
How to do it…
How it works…
See also
Managing Terraform resource dependencies
Getting ready
How to do it…
How it works…
There’s more…
See also
Adding custom pre and postconditions
Getting ready
How to do it…
How it works…
See also
Using checks for infrastructure validation
Getting ready
How to do it…
How it works…
There’s more…
See also
Scaling Your Infrastructure with Terraform
Technical requirements
Provisioning infrastructure in multiple environments
Getting ready
How to do it…
How it works…
See also
Provisioning multiple resources with the count meta-argument
Getting ready
How to do it…
How it works…
There’s more…
See also
Using maps
Getting ready
How to do it…
How it works…
There’s more…
See also
Looping over a map of objects
Getting ready
How to do it…
How it works…
There’s more…
See also
Generating multiple blocks with the dynamic block
Getting ready
How to do it…
How it works…
There’s more…
See also
Filtering maps
Getting ready
How to do it…
How it works…
There’s more…
See also
Using Terraform with External Data
Technical requirements
Obtaining external data with data sources
Getting ready
How to do it…
How it works…
There’s more…
See also
Querying external data with Terraform
Getting ready
How to do it…
How it works…
There’s more…
See also
Manipulating local files with Terraform
Getting ready
How to do it…
How it works…
There’s more…
See also
Executing local programs with Terraform
Getting ready
How to do it…
How it works…
There’s more…
See also
Executing shell scripts using the Terraform Shell provider
Getting ready
How to do it…
How it works…
There’s more…
See also
Managing Terraform State
Using the local Terraform state
Getting ready
How to do it…
How it works…
There’s more…
See also
Managing resources in Terraform state
Getting ready
How to do it…
Displaying the content of state
Listing Terraform resource names within state
Showing detailed resource properties in state
Deleting resources from state
There’s more…
See also
Synchronizing Terraform state
Getting ready
How to do it…
How it works…
There’s more…
See also
Importing existing resources
Getting ready
How to do it…
How it works…
There’s more…
See also
Using external resources from other Terraform state files
Getting ready
How to do it…
How it works…
There’s more…
See also
Refactoring resources in configuration
Getting ready
How to do it…
How it works…
There’s more…
See also
Applying a Basic Terraform Workflow
Technical requirements
Keeping your Terraform configuration clean
Getting ready
How to do it…
How it works…
There’s more…
See also
Validating the code syntax
Getting ready
How to do it…
How it works…
There’s more…
See also
Destroying infrastructure resources
Getting ready
How to do it…
How it works…
There’s more…
See also
Displaying a list of providers used in a configuration
Getting ready
How to do it…
How it works…
There’s more…
See also
Generating one Terraform lock file with Windows and Linux compatibility
Getting ready
How to do it…
How it works…
See also
Copying a Terraform module configuration
Getting ready
How to do it…
How it works…
There’s more…
See also
Using workspaces to manage environments
Getting ready
How to do it…
How it works…
There’s more…
See also
Exporting the output in JSON
Getting ready
How to do it…
How it works…
There’s more…
See also
Tainting resources
Getting ready
How to do it…
How it works…
There’s more…
See also
Generating the dependency graph
Getting ready
How to do it…
How it works…
See also
Using different Terraform configuration directories
Getting ready
How to do it…
How it works…
There’s more…
See also
Testing and evaluating a Terraform expression
Getting ready
How to do it…
How it works…
There’s more…
See also
Debugging the Terraform execution
Getting ready
How to do it…
How it works…
There’s more…
See also
Sharing Terraform Configuration with Modules
Technical requirements
Creating a Terraform module and using it locally
Getting ready
How to do it…
How it works…
There’s more…
See also
Provisioning multiple instances of a Terraform module
Getting ready
How to do it…
How it works…
There’s more…
See also
Using modules from the public registry
Getting ready
How to do it…
How it works…
There’s more…
See also
Sharing a Terraform module in the public registry using GitHub
Getting ready
How to do it…
How it works…
There’s more…
See also
Using another file inside a custom module
Getting ready
How to do it…
How it works…
There’s more…
See also
Using the Terraform module generator
Getting ready
How to do it…
How it works…
There’s more…
See also
Generating module documentation
Getting ready
How to do it…
How it works…
There’s more…
See also
Using a private Git repository for sharing a Terraform module
Getting ready
How to do it…
How it works…
There’s more…
See also
Applying a Terrafile pattern for using modules
Getting ready
How to do it…
How it works…
There’s more…
See also
Provisioning Azure Infrastructure with Terraform
Technical requirements
Using Terraform in Azure Cloud Shell
Getting ready
How to do it…
How it works…
There’s more…
See also
Protecting the Azure credential provider
Getting ready
How to do it…
How it works…
There’s more...
See also
Protecting the state file in the Azure remote backend
Getting ready
How to do it…
How it works…
There’s more…
See also
Executing ARM templates in Terraform
Getting ready
How to do it…
How it works…
There’s more…
See also
Executing Azure CLI commands in Terraform
Getting ready
How to do it…
How it works…
There’s more…
See also
Using Azure Key Vault with Terraform to protect secrets
Getting ready
How to do it…
How it works…
There’s more…
See also
Provisioning and configuring an Azure VM with Terraform
Getting ready
How to do it…
How it works…
There’s more…
See also
Building Azure serverless infrastructure with Terraform
Getting ready
How to do it…
How it works…
There’s more…
See also
Generating a Terraform configuration for existing Azure infrastructure
Getting ready
How to do it…
How it works…
There’s more…
See also
Enabling optional Azure features
Getting ready
How to do it…
How it works…
There’s more…
Estimating Azure cost of infrastructure using Infracost
Getting ready
How to do it…
How it works…
There’s more…
See also
Using the AzApi Terraform provider
Getting ready
How to do it…
How it works…
There’s more…
See also
Getting Starting to Provisioning AWS and GCP Infrastructure Using Terraform
Technical requirements
Getting started using Terraform for AWS
Getting ready
How to do it…
How it works…
There’s more…
See also
Using the S3 backend in AWS
Getting ready
How to do it…
How it works…
There’s more…
See also
Getting started using Terraform for GCP
Getting ready
How to do it…
How it works…
There’s more…
See also
Using a GCS backend in GCP
Getting ready
How to do it…
How it works…
See also
Executing Terraform in GCP Cloud Shell
Getting ready
How to do it…
How it works…
There’s more…
See also
Using Terraform for Docker and Kubernetes Deployment
Technical requirements
Creating a Docker container using Terraform
Getting ready
How to do it…
How it works…
There’s more…
See also
Deploying Kubernetes resources using Terraform
Getting ready
How to do it…
How it works…
There’s more…
See also
Deploying a Helm chart in Kubernetes using Terraform
Getting ready
How to do it…
How it works…
There’s more…
See also
Using a Kubernetes controller as a Terraform reconciliation loop
Getting ready
How to do it…
How it works…
There’s more…
See also
Running Test and Compliance Security on Terraform Configuration
Technical requirements
Using PowerShell’s Pester framework to perform Terraform testing
Getting ready
How to do it…
How it works…
There’s more…
See also
Testing the Terraform configuration using Python
Getting ready
How to do it…
How it works…
There’s more…
See also
Using OPA to check the Terraform configuration
Getting ready
How to do it…
How it works…
There’s more…
See also
Using tfsec to analyze the compliance of Terraform configuration
Getting ready
How to do it…
How it works…
There’s more…
See also
Applying Terraform compliance using terraform-compliance
Getting ready
How to do it…
How it works…
There’s more…
See also
Testing Terraform module code with Terratest
Getting ready
How to do it…
How it works…
There’s more…
See also
Testing the Terraform configuration using Kitchen-Terraform
Getting ready
How to do it…
How it works…
There’s more…
See also
Using the new integrated Terraform module integration test
Getting ready
How to do it…
How it works…
There’s more…
See also
Deep-Diving into Terraform
Technical requirements
Preventing resources from being destroyed
Getting ready
How to do it…
How it works…
There’s more…
See also
Ignoring manual changes
Getting ready
How to do it…
How it works…
There’s more…
See also
Using Terraform’s templating feature
Getting ready
How to do it…
How it works…
There’s more…
See also
Zero-downtime deployment with Terraform
Getting ready
How to do it…
How it works…
There’s more…
See also
Managing Terraform configuration dependencies using Terragrunt
Getting ready
How to do it…
How it works…
There’s more…
See also
Using Terragrunt as a wrapper for Terraform
Getting ready
How to do it…
How it works…
See also
Generating a self-signed SSL certificate using Terraform
Getting ready
How to do it…
How it works…
There’s more…
See also
Checking the configuration before committing code using Git hooks
Getting ready
How to do it…
How it works…
There’s more…
See also
Visualizing Terraform resource dependencies with Rover
Getting ready
How to do it…
How it works…
See also
Using the Terraform CDK for developers
Getting ready
How to do it…
How it works…
There’s more…
See also
Automating Terraform Execution in a CI/CD Pipeline
Running Terraform in automation mode
Getting ready
How to do it…
How it works…
There’s more…
See also
Displaying a summary of the execution of terraform plan
Getting ready
How to do it…
There’s more…
See also
Building CI/CD pipelines to apply Terraform configurations in Azure Pipelines
Getting ready
How to do it…
How it works…
There’s more…
See also
Automating Terraform execution in GitHub Actions
Getting ready
How to do it…
How it works…
There’s more…
See also
Working with workspaces in CI/CD
Getting ready
How to do it…
How it works…
There’s more…
See also
Building CI/CD for Terraform modules in Azure Pipelines
Getting ready
How to do it…
How it works…
There’s more…
See also
Building a workflow for publishing Terraform modules using GitHub Actions
Getting ready
How to do it…
How it works…
There’s more…
See also
Using Terraform Cloud to Improve Team Collaboration
Technical requirements
Authenticating Terraform to Terraform Cloud
Getting ready
How to do it…
There’s more…
See also
Managing workspaces in Terraform Cloud
Getting ready
How to do it…
How it works…
There’s more…
See also
Using the remote backend in Terraform Cloud
Getting ready
How to do it…
How it works…
There’s more…
See also
Migrating Terraform State to Terraform Cloud
Getting ready
How to do it…
How it works…
See also
Using Terraform Cloud as a private module registry
Getting ready
How to do it…
How it works…
There’s more…
See also
Executing Terraform configuration remotely in Terraform Cloud
Getting ready
How to do it…
How it works…
There’s more…
See also
Checking the compliance of Terraform configurations using OPA in Terraform Cloud
Getting ready
How to do it…
There’s more…
See also
Using integrated cost estimation for cloud resources
Getting ready
How to do it…
How it works…
There’s more…
See also
Integrating the Infracost run task during the Terraform Cloud run
Getting ready
How to do it…
How it works…
There’s more…
See also
Configuring Terraform Cloud with the Terraform TFE provider
Getting ready
How to do it…
There’s more…
See also
Troubleshooting Terraform Errors
Fixing interpolation errors
Getting ready
How to do it…
How it works…
See also
Fixing cycle errors
Getting ready
How to do it…
How it works…
There’s more…
Fixing for_each errors
Getting ready
How to do it…
There’s more…
Fixing output errors
Getting ready
How to do it…
How it works…
There’s more…
Terraform Cheat Sheet
Basic commands
Format Terraform configuration
Terraform providers management
Terraform dependency file
Basic workflow commands
Backend configuration
Validate configuration
Get outputs
Import resources
Terraform workspaces
Terraform debug
State management
Display Terraform graph dependencies
Taint/untaint resources
Terraform Cloud/Enterprise
Terraform Resources
Terraform official resources
Documentation
Registry
Providers development
Terraform community resources
Terraform news feed
Terraform certifications and certification preparation
Terraform certification program pages
Terraform certification preparation
Other Books You May Enjoy
Index