DEV Community

Cover image for How to Deploy Jenkins Server on AWS EC2 with Terraform
Dickson Victor for AWS Community Builders

Posted on

How to Deploy Jenkins Server on AWS EC2 with Terraform

Hi there! In this demo, I'll show you how to automate the installation of Jenkins and other softwares such as ansible, docker,AWS CLI and terraform on the AWS EC2 instance created using terraform. Jenkins is a popular open source continuous integration/continuous delivery and deployment (CI/CD) automation software DevOps tool. It is used to implement CI/CD workflows, called pipelines.

BEFORE YOU BEGIN

  1. Install AWS CLI and configure credentials.
  2. Install Terraform
  3. Clone the repository and "cd" into the folder.
  4. Create an EC2 keypair in your desired region and download it( I used us-east-1 and named it demoKP respectively in this demo) and ensure it's in the specified path( check the variables.tf file) Feel free to go through the cloned folder and peruse through the files. The Userdata.sh contains the scripts for the installation while the main.tf creates the EC2 infrastructure.

CREATING THE INFRASTRUCTURE
Run the following commands to begin the provisioning.

terraform init
terraform plan
terraform apply --auto-approve
Enter fullscreen mode Exit fullscreen mode

Output
Copy the url in the output to a browser

Browser
As suggested in the screenshot, ssh into the instance and run the command,sudo cat /var/lib/jenkins/secrets/initialAdminPassword in the terminal and paste the output into the box.( Don't forget to set the right permission on the keypair file).
It takes you to a getting started page, go ahead to click "Install suggested plugins"

Configure user
Go ahead to configure an admin user. You can use a dummy email address. On the next page, click the button Save and Finish and then Start using Jenkins
And then, taadahh! Jenkins is ready!

Jenkins
Go ahead to use it for your CI/CD workloads

DESTROY INFRASTRUCTURE
To destroy the infrastructure created with terraform, simply run the following command.

terraform destroy --auto-approve
Enter fullscreen mode Exit fullscreen mode

And that's How to deploy Jenkins server on AWS EC2 with Terraform. Thanks for reading.

Top comments (0)