{"id":26303,"date":"2019-03-18T15:51:05","date_gmt":"2019-03-18T20:51:05","guid":{"rendered":"https:\/\/centricconsulting.com\/?p=26303"},"modified":"2021-12-15T00:15:55","modified_gmt":"2021-12-15T05:15:55","slug":"part-2-scripting-gitlab-and-jenkins-installs-using-terraform-on-aws_devops","status":"publish","type":"post","link":"https:\/\/centricconsulting.com\/blog\/part-2-scripting-gitlab-and-jenkins-installs-using-terraform-on-aws_devops\/","title":{"rendered":"Part 2: Scripting GitLab and Jenkins Installs using Terraform on AWS"},"content":{"rendered":"

In this part of our series, learn how to build a practical solution in Amazon Web Services (AWS) using Terraform.<\/h2>\n

Part two of a four-part series<\/a>.<\/em><\/p>\n

In Part 1<\/u><\/strong><\/a>,<\/u><\/strong> I demonstrated how to build the core network infrastructure in AWS using an automation best practice:\u00a0Infrastructure-as-Code.<\/p>\n

With a few strokes of the keyboard we created a fully subnetted virtual private network with all the routing we will need to begin deploying our DevOps infrastructure.<\/p>\n

In this blog, I\u2019ll build on the existing infrastructure, adding open source continuous integration tools and the supporting infrastructure to provide a highly available deployment.<\/strong><\/p>\n

I\u2019ll continue to use Terraform as the tool of choice to script the deployment of a Jenkins master server, Jenkins slaves within an autoscaling group and a highly available GitLab repository behind a load balancer.<\/p>\n

Let\u2019s get started\u2026<\/h2>\n

To build out the application servers and associated infrastructure we continue to build out additional Terraform scripts which will provision the EC2 instances, application load balancers, RDS instances, Redis clusters, EFS (NAT) volumes, SSH key pairs, security groups and KMS Encryption keys.<\/p>\n

User Data<\/a> shell scripts and templates will also be created, which will install software and configure the applications and external resources. External resources, required for high availability, include multiple EFS volumes, a Redis cache cluster and a Postgresql database connection. I\u2019ll discuss what each service is and why we need it as we move along.<\/p>\n

main.tf<\/h4>\n

The main.tf script will utilize a Terraform template file to customize Gitlab. The template file \u201cgitlab_application_user_data.tpl\u201d contains generic configuration commands. In this script we will reference that script and pass is variables obtained from creating other resources, such as database instance name, userid, password and URL.<\/p>\n

First we create the database, then configure the EC2 instance to use values from the database creation process. We use the Terraform template construct to pass variables into the EC2 configuration script.<\/strong><\/p>\n

This script will also build the user_data for the EC2 instance using 2 objects; the rendered template (with interpolated variables) and a rendered shell script. The combined scripts will install and configure GitLab on an EC2 instance.<\/p>\n

Templates are a powerful advanced feature of Terraform which can be useful to pass Terraform outputs into your EC2 instance configuration scripts. For more information on Terraform template files, see the Terraform documentation page<\/a>.<\/strong><\/p>\n

\"AWS\"<\/a><\/p>\n

git.sh<\/h4>\n

The git.sh script, referenced in the main.tf script above, provides a simple bash script to perform the initial configuration of the GitLab EC2 instance.<\/p>\n

The function of this script is to:<\/strong><\/p>\n