An AWS EC2 setup running Jenkins provisioned via Terraform.
- Terraform 0.9+
-
Please ensure you have the
aws
cli application working -
Before you run this repo, ensure you've ran the
terraform-aws-init
repo. That will ensure you have theterraform-states
s3 bucket and aroot-ssh-key
for shell access to jenkins.
The scripts can be called with the following parameters:
tf-plan.sh <env_name> <region> <availability_zones> <ssh_key_name>
You can leave these blank if you provisioned in us-west-2 and just launch ./tf-plan.sh
Once the plan runs and everything looks good, you can provision your jenkins instance by running ./tf-apply.sh
That is all there is to it! You can then see the IP of your Jenkins instance and ssh or browse to it.
To ssh ssh admin@x.x.x.x
Jenkins UI can be seen browsed at x.x.x.x:8080
where x.x.x.x is the output IP address of the ec2 instance.
If you provision this Jenkins terraform script with something that deletes and creates a new Jenkins instance, (because yes that can happen) don't freak out. You can login to the AWS EC2->Volumes page and detach the new drive and add the old one back. All your Jenkins/Docker data should be stored on this volume.
- SSH into Jenkins and stop Jenkins
sudo service jenkins stop
- Unmount the new drive
sudo umount /dev/xvdf
- Detach the volume in the AWS dashboard.
Delete drives not in use anymore as they will pile up even after a terraform destroy.
Just run ./tf-destroy.sh
but in order to finalize cleanup you'll need to delete one last thing manually.
There is a 250 GB drive mounted to Jenkins that is not destroyed when you destroy the instance with terraform, you have to manually goto AWS EC2 Volumes and destroy the drive that way.
This is to prevent critical production data from getting destroyed but yea, I even keep forgetting to kill these drives...
This could probably be further improved by using Ansible, Puppet, Chef, or something like that to provision any OS. This is really locked to Debian at the moment.