Infrastructure as Code for Beginners

Book description

Master Infrastructure as Code (IaC) and streamline your DevOps workflows using Terraform and Ansible Purchase of the print or Kindle book includes a free eBook in the PDF format

Key Features

  • Employ effective strategies and approach IaC projects efficiently by diving deep into its fundamentals
  • Understand the working of Terraform and Ansible and integrate them into your CI/CD workflows
  • Work with real-world examples of IaC across multiple cloud providers (Azure & AWS)

Book Description

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.

What you will learn

  • Determine the right time to implement Infrastructure as Code for your workload
  • Select the appropriate approach for Infrastructure-as-Code deployment
  • Get hands-on experience with Ansible and Terraform and understand their use cases
  • Plan and deploy a workload to Azure and AWS clouds using Infrastructure as Code
  • Leverage CI/CD in the cloud to deploy your infrastructure using your code
  • Discover troubleshooting tips and tricks to avoid pitfalls during deployment

Who this book is for

This book is for cloud engineers, software developers, or system administrators responsible for deploying resources to host applications. Ideal for both beginners and experienced professionals seeking to deepen their knowledge. Experience in manually deploying resources for applications in public clouds such as AWS or Microsoft Azure is a must. A basic understanding of programming or scripting languages, such as Python, Bash, PowerShell, etc. as well as familiarity with version control systems like Git, is a prerequisite.

Table of contents

  1. Infrastructure as Code for Beginners
  2. Contributors
  3. About the author
  4. About the reviewer
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Download the color images
    6. Conventions used
    7. Get in touch
    8. Share Your Thoughts
    9. Download a free PDF copy of this book
  6. Part 1: The Foundations – An Introduction to Infrastructure as Code
  7. Chapter 1: Choosing the Right Approach – Declarative or Imperative
    1. The challenges of managing infrastructure manually
      1. My own journey
      2. Today’s challenges
      3. Conclusion
    2. What is meant by declarative and imperative?
      1. Basic Infrastructure-as-Code project
      2. Declarative approach
      3. Imperative approach
    3. Pets versus cattle
      1. Pets
      2. Cattle
      3. Conclusion
    4. What does all this mean for our Infrastructure-as-Code deployments?
    5. Summary
    6. Further reading
  8. Chapter 2: Ansible and Terraform beyond the Documentation
    1. What is important when choosing a tool?
      1. Deployment types
      2. Infrastructure and configuration
      3. External interactions and secrets
      4. Ease of use
      5. Summary
    2. Introducing Terraform
      1. An HCL example – creating a resource group
      2. Adding more resources
    3. Introducing Ansible
      1. An Ansible example
    4. Introducing Visual Studio Code
    5. Summary
    6. Further reading
  9. Chapter 3: Planning the Deployment
    1. Planning the deployment of our workload
    2. How to approach the deployment of our infrastructure
      1. Deployment considerations
      2. Performing deployment tasks
      3. Introducing cloud-init
    3. Exploring the high-level architecture
    4. Summary
    5. Further reading
  10. Part 2: Getting Hands-On with the Deployment
  11. Chapter 4: Deploying to Microsoft Azure
    1. Technical requirement
    2. Introducing and preparing our cloud environment
      1. Preparing our cloud environment for deployment
    3. Producing the low-level design
    4. Terraform – writing the code and deploying our infrastructure
      1. Setting up the Terraform environment
      2. Creating a resource group
      3. Networking
    5. Ansible – reviewing the code and deploying our infrastructure
      1. Ansible Playbook roles overview
      2. Running the Ansible Playbook
    6. Summary
    7. Further reading
  12. Chapter 5: Deploying to Amazon Web Services
    1. Technical requirements
    2. Introducing Amazon Web Services
    3. Preparing our cloud environment for deployment
    4. Producing the low-level design
    5. Ansible – writing the code and deploying our infrastructure
      1. Ansible playbook roles
      2. Running the Ansible playbook
    6. Terraform – reviewing the code and deploying our infrastructure
      1. Walk-through of Terraform files
      2. Deploying the environment
    7. Summary
    8. Further reading
  13. Chapter 6: Building upon the Foundations
    1. Understanding cloud-agnostic tools
    2. Understand the differences between our Microsoft Azure and Amazon Web Services deployments
      1. General
      2. Network
      3. Storage
      4. Virtual machine (admin)
      5. Virtual machines with scaling (web)
      6. Seeing it in action
    3. Understanding the differences between our Terraform and Ansible deployments
    4. Introducing more variables
    5. Making the code more reusable
    6. Pop quiz
    7. Summary
    8. Further reading
    9. Answers
  14. Part 3: CI/CD and Best Practices
  15. Chapter 7: Leveraging CI/CD in the Cloud
    1. Technical requirements
    2. Introducing GitHub Actions
    3. Running Terraform using GitHub Actions
      1. Terraform state files
      2. GitHub Actions
    4. Running Ansible using GitHub Actions
    5. Security best practices
    6. Pop quiz
    7. Summary
    8. Further reading
    9. Answers
  16. Chapter 8: Common Troubleshooting Tips and Best Practices
    1. Technical requirements
    2. Infrastructure as Code – best practices and troubleshooting
      1. General IaC best practices
      2. General IaC troubleshooting tips
    3. Terraform – best practices and troubleshooting
      1. Terraform – best practices
      2. Terraform – troubleshooting
    4. Ansible – best practices and troubleshooting
      1. Ansible – best practices
      2. Ansible – troubleshooting
    5. Summary
  17. Chapter 9: Exploring Alternative Infrastructure-as-Code Tools
    1. Technical requirements
    2. Getting hands-on with Pulumi
      1. Using Pulumi and YAML
      2. Using Pulumi and Python
    3. Getting hands-on knowledge of Azure Bicep
      1. Working through the Bicep file
      2. Deploying the Bicep file
    4. Getting hands-on with AWS CloudFormation
      1. AWS CloudFormation template
      2. Using the AWS CLI to deploy
      3. Using the AWS Management Console to deploy
    5. Summary
    6. Further reading
  18. Index
    1. Why subscribe?
  19. Other Books You May Enjoy
    1. Packt is searching for authors like you
    2. Share Your Thoughts
    3. Download a free PDF copy of this book

Product information

  • Title: Infrastructure as Code for Beginners
  • Author(s): Russ McKendrick
  • Release date: May 2023
  • Publisher(s): Packt Publishing
  • ISBN: 9781837631636