Chapter 2 overview

How to Manage Your Infrastructure as Code

Learn how to manage your infrastructure as code using tools such as ad hoc scripts (e.g., Bash, Ruby), configuration management tools (e.g., Ansible, Chef, Puppet), server templating tools (e.g., Packer, Docker), and provisioning tools (e.g., Terraform, OpenTofu, Pulumi).

Key ideas you'll learn

  • Ad hoc scripts
  • Configuration management tools
  • Server templating tools
  • Provisioning tools

Examples you'll try

  • Use Bash to deploy an EC2 instance
  • Use Ansible to deploy an EC2 instance
  • Use Packer to build an AMI
  • Use OpenTofu to deploy an EC2 instance

Table of contents

2.1 The Benefits of IaC
2.2 Ad Hoc Scripts
2.2.1 Example: Deploy an EC2 Instance Using a Bash Script
2.2.2 How Ad Hoc Scripts Stack Up
2.3 Configuration Management Tools
2.3.1 Example: Deploy an EC2 Instance Using Ansible
2.3.2 Example: Configure a Server Using Ansible
2.3.3 How Configuration Management Tools Stack Up
2.4 Server Templating Tools
2.4.1 Example: Create a VM Image Using Packer
2.4.2 How Server Templating Tools Stack Up
2.5 Provisioning Tools
2.5.1 Example: Deploy an EC2 Instance Using OpenTofu
2.5.2 Example: Update and Destroy Infrastructure Using OpenTofu
2.5.3 Example: Deploy an EC2 Instance Using an OpenTofu Module
2.5.4 Example: Deploy an EC2 Instance Using an OpenTofu Registry Module
2.5.5 How Provisioning Tools Stack Up
2.6 Using Multiple IaC Tools Together
2.6.1 Provisioning Plus Configuration Management
2.6.2 Provisioning Plus Server Templating
2.6.3 Provisioning Plus Server Templating Plus Orchestration
2.7 Adopting IaC
2.8 Conclusion

Related Books

Terraform: Up & Running: Writing Infrastructure as Code

By Yevgeniy Brikman (O'Reilly)

recommended same-author

Terraform has emerged as a key player in the DevOps world for defining, launching, and managing infrastructure as code (IAC) across a variety of cloud and virtualization platforms, including AWS, Google Cloud, and Azure. This hands-on book is the fastest way to get up and running with Terraform. Gruntwork co-founder Yevgeniy (Jim) Brikman walks you through dozens of code examples that demonstrate how to use Terraform’s simple, declarative programming language to deploy and manage infrastructure with just a few commands. Whether you’re a novice developer, aspiring DevOps engineer, or veteran sysadmin, this book will take you from Terraform basics to running a full tech stack capable of supporting a massive amount of traffic and a large team of developers.

Infrastructure as Code: Dynamic Systems for the Cloud Age

By Kief Morris (O'Reilly)

recommended

Just five years ago, infrastructure as code was a new concept for many companies. Today, even banks, governments, and other highly regulated organizations are moving to the cloud, leading teams everywhere to build up large, complex infrastructure codebases. With this practical book, Kief Morris of ThoughtWorks shows you how to effectively use principles, practices, and patterns pioneered by infrastructure and development teams to manage cloud age infrastructure. Ideal for system administrators, infrastructure engineers, software developers, team leads, and architects, this insightful second edition demonstrates the tools you need for implementing infrastructure as code. You'll learn about the platforms and tooling involved in creating and configuring infrastructure elements, patterns for using these tools, and practices for making infrastructure as code work in your environment.

Ansible for DevOps: Server and configuration management for humans

By Jeff Geerling (Midwestern Mac)

Ansible is a simple, but powerful, server and configuration management tool (with a few other tricks up its sleeve). This book will help those familiar with the command line and basic shell scripting start using Ansible to provision and manage anywhere from one to thousands of servers.

Other Related Resources

How to find AMI IDs for Amazon Linux and Ubuntu

By Yevgeniy Brikman (Blog post)

recommended same-author

Learn the several copy-pasteable recipes for programmatically finding the IDs of the latest Amazon-managed AMIs, such as Amazon Linux and Ubuntu, using tools such as the AWS CLI, OpenTofu, Packer, Ansible, and AWS SSM Parameter Store.

Reusable, composable, battle-tested Terraform modules

By Yevgeniy Brikman (Talk)

same-author

Listen up, developers. You are not special. Your infrastructure is not a beautiful and unique snowflake. You have the same tech debt as everyone else. So why are you reinventing the wheel? Why are you building the same infrastructure, from scratch, over and over again?.

5 Lessons Learned from Writing Over 300,000 Lines of Infrastructure Code

By Yevgeniy Brikman (Talk, blog post)

same-author

This October, I gave a talk at HashiConf 2018 where I shared 5 key lessons we learned at Gruntwork while creating and maintaining a library of over 300,000 lines of infrastructure code that’s used in production by hundreds of companies. In this blog post, I’ll share with you the video and slides from the talk, as well as a condensed, written version of the 5 key lessons.

Infrastructure as Code Best Practices

By Yevgeniy Brikman (Podcast)

same-author

Yevgeniy Brikman, author of Terraform: Up & Running and co-founder of Gruntwork talks with host Robert Blumen about how to apply best practices from software engineering to the development of infrastructure as code, primarily with Terraform. The discussion covers similarities and differences between conventional software engineering and code-driven infrastructure; factoring code into modules; layering; terraform code organization for micro-services; releases and tagging; code reviews; unit testing infrastructure; deployment of infrastructure; ownership and code structure models; and open source and re-usable libraries.

What is Infrastructure as Code?

By Beau Carnes (Online course)

What is Infrastructure as Code? In this article you will learn all about Infrastructure as Code. I will start with an overview of the general concepts, and then I will show you how to implement Infrastructure as Code with three different labs.

IaC Learning Path

By KodeKloud (Online course)

Explore the Infrastructure as Code (IaC) training roadmap designed by our industry experts. Master the art of IaC with proven study roadmap and resources.

Configuration Management Tools

Ansible

used-in-book

Ansible offers open-source automation that is simple, flexible, and powerful.

Chef

Chef Software's DevOps automation tools enable the coded enterprise to overcome complexity with infrastructure, security and application automation for your technology.

Puppet

Puppet is the industry-leading automation solution for configuration management, compliance, CI/CD, patch management, IT automation, and more.

VM Hypervisor Tools

VMware vSphere

Get the power of VMware vSphere, a top enterprise workload engine. Boost workload performance, improve security, and speed up innovation for your business.

VirtualBox

VirtualBox is a general-purpose full virtualization software, targeted at laptop, desktop, server and embedded use.

Parallels

Download Parallels to run Windows on Mac, Chrome, gain access to virtual desktop infrastructure (VDI) with DaaS, & Toolbox to secure private files, & more.

Nitro

AWS Nitro System is a lightweight hypervisor that provides improved compute and networking performance for EC2 instances.

VM Image Tools

Packer

recommended used-in-book

Use Packer to create golden images for multiple platforms from a single source configuration.

Vagrant

Vagrant enables users to create and configure lightweight, reproducible, and portable development environments.

Micro VMs Tools

Firecracker

Secure and fast microVMs for serverless computing.

v8 isolates

Lightweight contexts that provide your code with variables it can access and a safe environment to be executed within. You could even consider an isolate a sandbox for your function to run in.

WebAssembly

WebAssembly (abbreviated Wasm) is a binary instruction format for a stack-based virtual machine. Wasm is designed as a portable compilation target for programming languages, enabling deployment on the web for client and server applications.

Container Engine Tools

Docker

recommended used-in-book

Docker is a platform designed to help developers build, share, and run container applications. We handle the tedious setup, so you can focus on the code.

Moby

The Moby Project - a collaborative project for the container ecosystem to assemble container-based systems.

CRI-O

Lightweight Container Runtime for Kubernetes.

Podman

Manage containers, pods, and images with Podman. Seamlessly work with containers and Kubernetes from your local environment.

runc

CLI tool for spawning and running containers according to the OCI specification.

buildkit

Concurrent, cache-efficient, and Dockerfile-agnostic builder toolkit.

Provisioning Tools

OpenTofu

recommended used-in-book

The open source infrastructure as code tool.

Terraform

Terraform is an infrastructure as code tool that enables you to safely and predictably provision and manage infrastructure in any cloud.

CloudFormation

AWS CloudFormation is an infrastructure as code (IaC) service that allows you to easily model, provision, and manage AWS and third-party resources.

OpenStack Heat

Heat is the main project in the OpenStack Orchestration program. It implements an orchestration engine to launch multiple composite cloud applications based on templates in the form of text files that can be treated like code.

Pulumi

Pulumi is an infrastructure management platform to automate through infrastructure as code, secure with secrets management, and manage infrastructure with AI.

Module Registry Tools

Ansible Galaxy

Jump-start your automation project with great content from the Ansible community. Galaxy provides pre-packaged units of work known to Ansible as roles and collections. Content from roles and collections can be referenced in Ansible playbooks and immediately put to work. You'll find content for provisioning infrastructure, deploying applications, and all of the tasks you do everyday.

Docker Hub

recommended used-in-book

Welcome to the world's largest container registry built for developers and open source contributors to find, use, and share their container images. Build, push and pull.

OpenTofu Registry

recommended used-in-book

A fast and easy-to-use UI for quickly browsing and viewing OpenTofu modules and providers.

Terraform Registry

Discover Terraform providers that power all of Terraform's resource types, or find modules for quickly deploying common infrastructure configurations.

Gruntwork Infrastructure as Code Library

same-author

Production-ready IaC modules for AWS. Leverage a catalog of 300+ battle-tested Terraform/OpenTofu modules to set up your AWS foundations, run apps, and store data.

Comments