5 Discovering Jenkins as code with Terraform

 

This chapter covers

  • Introducing infrastructure as code (IaC)
  • Using HashiCorp Terraform, which enables IaC
  • Deploying Jenkins in a secure private network
  • Scaling Jenkins workers dynamically with AWS Auto Scaling

In the previous chapter, we used HashiCorp Packer to create custom Jenkins machine images; in this chapter, we will use those images (figure 5.1) to deploy the machines. To do that, 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.

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.

Figure 5.1 Jenkins custom machine images

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 autoscaling the Jenkins worker pool

5.5.1 Launch configuration

5.5.2 Auto Scaling group

5.5.3 Autoscaling scaling policies

5.5.4 Workers CPU utilization load