Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
The Linux DevOps Handbook

You're reading from  The Linux DevOps Handbook

Product type Book
Published in Nov 2023
Publisher Packt
ISBN-13 9781803245669
Pages 428 pages
Edition 1st Edition
Languages
Concepts
Authors (2):
Damian Wojsław Damian Wojsław
Profile icon Damian Wojsław
Grzegorz Adamowicz Grzegorz Adamowicz
Profile icon Grzegorz Adamowicz
View More author details

Table of Contents (20) Chapters

Preface 1. Part 1: Linux Basics
2. Chapter 1: Choosing the Right Linux Distribution 3. Chapter 2: Command-Line Basics 4. Chapter 3: Intermediate Linux 5. Chapter 4: Automating with Shell Scripts 6. Part 2: Your Day-to-Day DevOps Tools
7. Chapter 5: Managing Services in Linux 8. Chapter 6: Networking in Linux 9. Chapter 7: Git, Your Doorway to DevOps 10. Chapter 8: Docker Basics 11. Chapter 9: A Deep Dive into Docker 12. Part 3: DevOps Cloud Toolkit
13. Chapter 10: Monitoring, Tracing, and Distributed Logging 14. Chapter 11: Using Ansible for Configuration as Code 15. Chapter 12: Leveraging Infrastructure as Code 16. Chapter 13: CI/CD with Terraform, GitHub, and Atlantis 17. Chapter 14: Avoiding Pitfalls in DevOps 18. Index 19. Other Books You May Enjoy

CI/CD with Terraform, GitHub, and Atlantis

In this chapter, we are going to build on the previous chapters in this book by introducing pipelines for continuous integration (CI) and continuous deployment (CD). There are many CI and CD tools available for you, both open source and closed source, as well as self-hosted and Software-as-a-Service (SaaS). We are going to demonstrate an example pipeline, starting from committing source to the repository where we store Terraform code to applying changes in your infrastructure. We will do this automatically but with reviews from your team.

In this chapter, we are going to cover the following topics:

  • What is CI/CD?
  • Continuously integrating and deploying your infrastructure
  • CI/CD with Atlantis

Technical requirements

For this chapter, you will need the following:

  • A Linux box
  • A free account on GitHub or similar platform (GitLab or Bitbucket)
  • The latest version of Terraform
  • The AWS CLI
  • Git

What is CI/CD?

CI/CD is a set of practices, tools, and processes that allow software development teams to automate the building, testing, and deployment of their applications, enabling them to release software more frequently and with greater confidence in its quality.

Continuous integration (CI) is a practice where developers regularly integrate their code changes into a repository, and each integration triggers an automated build and test process. This helps catch errors early and ensures that the application can be built and tested reliably.

For example, using Docker, a developer can set up a CI pipeline that automatically builds and tests their application whenever changes are pushed to the code repository. The pipeline can include steps to build a Docker image, run automated tests, and publish the image to a Docker registry.

Continuous delivery is the practice of getting software to be available for deployment after the successful integration process. For example, with...

Continuously integrating and deploying your infrastructure

Testing application code is now a de facto standard, especially since the adoption of test-driven development (TDD). TDD is a software development process in which developers write automated tests before writing code.

These tests are designed to fail initially, and developers then write code to make them pass. The code is continuously refactored to ensure it is efficient and maintainable while passing all tests. This approach helps reduce the number of bugs and increase the reliability of the software.

Testing infrastructure is not as easy as that as it’s hard to check whether Amazon Elastic Compute Cloud (EC2) will be successfully started without actually starting the instance. It’s possible to mock API calls to AWS, but it won’t guarantee that the actual API will return the same results as your testing code. With AWS, it would also mean that testing will be slow (we will need to wait for this EC2...

CI/CD with Atlantis

Armed with the knowledge about tooling and principles around CI/CD (both delivery and deployment), we will create a CI/CD pipeline with the use of Git and the open source tool Atlantis. We will automatically test and deploy changes to our AWS infrastructure with it and do basic testing along the way.

Deploying Atlantis to AWS

We will use the Terraform module created by Anton Bobenko from the terraform-aws-modules project on GitHub. Here is the Terraform Registry link to the module: https://registry.terraform.io/modules/terraform-aws-modules/atlantis/aws/latest.

You can use this module in two ways. First, which is natural, is using it in your existing Terraform code to deploy it in AWS. The second, which we will use for this demonstration, is using the module as a standalone project. The module will also create a new Virtual Private Cloud (VPC) for you in the eu-west AWS zone and Atlantis will be running inside the AWS ECS service. This will generate some...

Summary

In this chapter, we explored the benefits of using Terraform for IaC and discussed the importance of incorporating CI/CD processes in Terraform workflows. We covered testing infrastructure and various tools for automating deployment.

In the final section, we explained how to deploy Atlantis, an open source tool for automated Terraform pull request previews, to AWS and configure GitHub to trigger terraform plan and terraform apply. With Atlantis, Terraform users can collaborate on infrastructure changes through GitHub pull requests, allowing for infrastructure changes to be reviewed and approved before they are applied to production. By incorporating Atlantis into your Terraform workflow, you can improve collaboration, reduce errors, and achieve faster and more secure infrastructure changes.

In the final chapter, we will slow down a little and talk about DevOps misconceptions and antipatterns, and how to avoid them.

Exercises

Try out the following exercises to test your knowledge of this chapter:

  1. Try to deploy Atlantis locally by following the documentation found at https://www.runatlantis.io/guide/testing-locally.html.
  2. Create a repository and configure the webhook and PAT for yourself. Run a plan for your new repository (hint: instead of AWS resources, you can use a null resource for testing).
  3. Create an account on one of the CD solution websites and try to run a plan using this SaaS. There’s usually a free plan for public repositories.
lock icon The rest of the chapter is locked
You have been reading a chapter from
The Linux DevOps Handbook
Published in: Nov 2023 Publisher: Packt ISBN-13: 9781803245669
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime}