Book Image

Infrastructure as Code for Beginners

By : Russ McKendrick
4 (1)
Book Image

Infrastructure as Code for Beginners

4 (1)
By: Russ McKendrick

Overview of this book

The Infrastructure as Code (IaC) approach ensures consistent and repeatable deployment of cloud-based IaaS/PaaS services, saving you time while delivering impeccable results. Infrastructure as Code for Beginners is a practical implementation guide that helps you gain a clear understanding of the foundations of Infrastructure as Code and make informed decisions when implementing it. With this book, you’ll uncover essential IaC concepts, including planning, selecting, and implementing the right tools for your project. With step-by-step explanations and real-world examples, you'll gain a solid understanding of the benefits of IaC and the scope of application in your projects. You'll learn about the pros, cons, and best practices of different IaC tools such as Terraform and Ansible, and their use at different stages of the deployment process along with GitHub Actions. Using these tools, you'll be able to design, deploy, and secure your infrastructure on two major cloud platforms, Microsoft Azure and Amazon Web Services. In addition, you'll explore other IaC tools such as Pulumi, AWS CloudFormation, and Azure Bicep. By the end of this book, you’ll be well equipped to approach your IaC projects confidently.
Table of Contents (15 chapters)
1
Part 1: The Foundations – An Introduction to Infrastructure as Code
5
Part 2: Getting Hands-On with the Deployment
9
Part 3: CI/CD and Best Practices

Introducing more variables

Personally, I try to do everything I can use variables rather than hardcoding values into the code itself – while this can take more time when it comes to writing your code, I highly recommend it as both tools we have looked at allow you to override variables at runtime via the command line.

To do this in Terraform, you can use the following flag when running the apply command:

$ terraform apply -var region="eu-west-1"

When running the Terraform code, which we discussed earlier in the chapter, we launched a network in Amazon Web Services to change the region from us-east-1, which is the default set within the code, to eu-west-1 instead.

You can add multiple variables; the following example expands on the previous one by adding a new address space to use:

$ terraform apply -var region="eu-west-1" -var address_space="172.16.0.0/24"

When running Ansible code, for example, in the playbook we executed in the...