You were recently hired as an Infrastructure Automation Engineer at a SaaS company. The company is trying to move away from cloud-provider-specific infrastructure as code. They want to test out Terraform for infrastructure deployment as it is cloud agnostic and Ansible as it is OS agnostic and also a hybrid IaC tool.
Your first task is to use Terraform and Ansible to deploy a distributed Jenkins CI/CD pipeline and put it behind one of the company’s DNS domains for testing. It sounds easy enough but there’s quite some planning which will go into this and you’re already on top of it.
Successfully complete this lab by achieving the following learning objectives:
- Log in to the Terraform Controller Node EC2 Instance
Find the details for logging in to the Terraform Controller node provided by the hands-on lab interface and log in to the node using SSH.
Note: This Instance already has an EC2 instance profile (role) attached to it and has all necessary AWS API permissions required for this lab. It also has the AWS CLI set up and is configured with the AWS account attached to this lab, for which the console login credentials are also provided in the lab interface page once the lab spins up.
After logging in, check the version of Terraform that is installed. Execute the following command to check:
- Clone the GitHub Repo for Terraform Code
gitcommand to clone the GitHub repo which has the Terraform code to deploy to complete this lab. GitHub repo URL.
Execute the following command:
git clone https://github.com/ACloudGuru-Resources/-content-deploying-to-aws-ansible-terraform.git
Change directory to the directory for lab Terraform code:
lsand examine the contents of the directory you’re in.
- Deploy the Terraform Code
terraform initto initialize the Terraform directory you changed into to download the required provider.
terraform fmtto ensure Terraform code is formatted properly.
terraform validateto ensure code has proper syntax and no errors.
terraform planand enter
yeswhen prompted to see the execution plan and note the number of resources that will be created.
terraform applyand enter
yeswhen prompted to actually deploy resources.
terraform applyhas run successfully, you can either use AWS CLI on the Controller node to list, describe created resources, and additionally also log in to the AWS Console to verify and investigate created resources.
Finally, on the Terraform Controller node CLI, execute
terraform destroyand enter
yeswhen prompted to delete all resources which were created and ensure that it runs through successfully.
- Test Out Your Deployment
- Username: admin
- Password password
Test your deployment by carrying out the following steps:
- Test out the URL of your website returned in Terraform outputs.
- Changing the workers count by modifying
workers-countvariable in the
variables.tffile and ensure that Terraform apply is successful. You can also log in to Jenkins, go in to Settings, and under the Manage nodes setting, check that the number of Jenkins workers you had set up are the number of workers showing as integrated with the Jenkins Master node.
Use the variable
variables.tffile to tie down SSH access to Jenkins nodes only from your home/work IP or from the Terraform Controller node. You can also pass in your current public IP through the
external_ipvariable dynamically on the CLI via something like this:
terraform apply -var external_ip=$(curl ifconfig.me)/32
This should pass your public IP in
x.x.x.x/32format to the
ifconfig.meis just one method to find your public URL. Feel free to use whatever method you prefer.