Install Jenkins using Docker and Terraform in AWS Cloud

Sergey Yanover
2 min readJul 1, 2021

You may choose Amazon Web Services (AWS) as a Cloud Infrastructure Provider.

I’d like to install Jenkins based on docker image in AWS Cloud. I am going to install whole infrastructure from scratch using Terraform, install Docker, Git, Jenkins on Amazon Linux on EC2 t2.micro instance automatically with bash and groovy scripts.

You should have AWS account, have generated SSH keys, have installed git, terraform on your local computer and enough skills to avoid paying more then need.
Using AWS console, choose IAM (Identity and Access Management) and create user terraform with Access type “Programmatic access” and attach group of policies “AdministratorAccess” directly.

Install scripts from GitHub on your local computer:

mkdir jenkins
cd jenkins
git clone https://github.com/sergeyanover/jenkins-docker-terraform-aws.git
cd jenkins-docker-terraform-aws

Generated keys for a user terraform you should put into a file varset.bat AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and set the region, I use eu-central-1.
Generate SSH public and private keys with puttygen.exe and save them in folder “keys”.

Edit file terraform.tfvars in folder “terraform” and put your public key like “ssh-rsa …” into it as a value of my_public_key. In addition, you should set your current IP address or your network in ip_admin.
You may know your IP address just click https://www.whatismyip.com or other resources.

cd terraform
terraform init
terraform plan
terraform apply

You will see the proccess of creation: key pair, vpc, internet gateway, subnet, security groups, route table, instance.
Also, you will see the Output: ec2_public_ip = “xx.xx.xx.xx”

You can use this IP to connect to Jenkins on port 8080: https//xx.xx.xx.xx:8080 with a temporarily pair “admin - password” which you should change later.

Your Jenkins based on EC2 machine t2.micro with Amazon Linux is ready to work.

--

--