Skip to content

dobby-dobster/aws-terraform-ansible-jenkins-env

Repository files navigation

Distributed, multi-region, jenkins deployment using Terraform and Ansible

logo

AWS services used:

  • S3
  • VPC
  • EC2
  • Route 53
  • ALB
  • ACM
  • IAM

Regions: us-east-1 and us-west-2

Prerequisites

  • AWS account
  • AWS credentails populated in ~/.aws/credentials. You can run aws configure to populate this file.
  • AWS CLI installed on machine where you plan to deploy from
  • Terraform (version 12.0.0+) installed on machine where you plan to deploy from
  • Ansible installed on machine where you plan to deploy from
  • Python boto3 and botocore modules installed on machine where you plan to deploy from pip install boto3
  • A domain registered within Route53

Versions I used:

  • OS Ubuntu 16.04
  • Terraform v0.13.3
  • Ansible 2.9.9
  • aws-cli 1.18.69

Getting started

Firstly clone this repo and then cd into the repo directory.

Next, before you can deploy this environment, you need to create an AWS S3 bucket. This bucket is used to store Terraform state.

aws s3api create-bucket --bucket <bucket name>

Populate the above command with a unique name of your S3 bucket.

You need to change the terraform code so it knows the name of your S3 bucket you created earlier. The file that needs updating is backend.tf

  backend "s3" {
    region  = "us-east-1"
    profile = "default"
    key     = "terraformstatefile"
    bucket  = "<CHANGE ME>"
  }
}

Next, create a ssh key which will be deloyed to each of the ec2 instance. You can change the location of where your ssh key file is output if you want, but you need to ensure you update instances.tf with the new location.

ssh-keygen -f /var/tmp/aws_id_rsa -t rsa

Finally update variables.tf with your domain. The value needs to contain a '.' at the end.

  type    = string
  default = "XXX."
}

Deploy

You can now deploy the environment with Terraform.

terraform plan will show you what terraform plans to do, i.e how many resources it will add.

If you are happy with the output, then terraform apply. Type 'yes' when prompted.

End Result

Once the deployment has completed, a multi-region Jenkins deployment will exist - master in us-east-1 and a worker node in us-west-2.

You will be able to access jenkins via https://jenkins. + your-domain. Login credentials are admin/password

Pre-populated jobs (aka projects) will also be deployed,such as "Create_Delete_S3_Bucket" which can be used to create or delete S3 buckets.

logo

logo

Cleanup

You can destroy the environment with terraform destroy.

This will remove all resources apart from the S3 bucket. To destroy the S3 bucket you can use the aws cli command aws s3 rb s3://bucket-name --force

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published