chapter five

5 Discovering Jenkins as Code with Terraform

 

This chapter covers

  • Overview of Infrastructure as Code (IaC).
  • Usage of Terraform and how it enables IaC.
  • Deployment of Jenkins in a secure private network.
  • Scaling Jenkins workers dynamically with AWS Autoscaling.

In the previous chapter, we have used HashiCorp Packer to create custom Jenkins machine images; in this chapter, we will use those images (figure below) to deploy the machines. The only difference, we will write declarative definitions of the Jenkins infrastructure we want to exist and use an automation tool to deploy the resources on the given Infrastructure as a Service (IaaS) provider.

Figure 5.1. Jenkins custom machine images

In the past, managing IT infrastructure was a hard job. System administrators had to manually manage and configure all of the hardware and software that was needed for the applications to run. However, in recent years, things have changed dramatically. Trends like cloud computing revolutionized—and improved—the way organizations design, develop, and maintain their IT infrastructure. One of the critical components of this trend is called infrastructure as code.

5.1      Introducing Infrastructure as Code

5.1.1   Terraform Usage

5.2      Provisioning an AWS VPC

5.2.1   AWS VPC

5.2.2   VPC Subnets

5.2.3   VPC Route Tables

5.2.4   VPC Bastion Host

5.3      Setting up a Self-healing Jenkins master

5.4      Running Jenkins with native SSL/HTTPS

5.5      Dynamically auto-scaling Jenkins worker pool

5.5.1   Launch Configuration

5.5.2   Auto-Scaling Group

5.5.3   Auto-Scaling Scaling Policies

5.5.4   Workers CPU Utilization Load

5.6      Summary