DevOps Lab Infrastructure Setup Guide on AWS
Estimated Cost: ~$1/day
This guide provides detailed instructions for setting up the necessary infrastructure on AWS to support the CI/CD labs in our curriculum. By following this guide, educators and learners will be able to prepare a robust environment for hands-on practice with continuous integration and continuous delivery.
Prerequisites
Before setting up the infrastructure for the CI/CD labs on AWS, ensure that you have the following tools installed and configured on your machine. These tools are necessary for interacting with AWS services and for deploying and managing the infrastructure.
Software Requirements
Name | Purpose | Installation Guide |
---|---|---|
AWS CLI | To interact with Amazon Web Services. | Guide Link |
Terraform | To provision AWS Infrastructure consistently and programmatically. | Guide Link |
Git | To clone the infrastructure scripts. | Guide Link |
WireGuard Client | To access internal services. | Guide Link |
Other Requirements
Active AWS Account: You need an active AWS account to provision AWS services. You will be billed accordingly for the AWS resources utilized during the labs.
Configuring AWS CLI
Obtain Access Credentials
- Log into your AWS Management Console.
- Navigate to
IAM > Users
. - Click
Create user
. - Enter the desired user name, click next, and attach the
AdministratorAccess
policy. - After creation, click on the new user and navigate to the
Security credentials
tab, and clickCreate access key
. - Generate a new access key for the Command Line Interface user case. Make sure to save these credentials securely.
Configure the AWS CLI
- Open your terminal.
- Run the following command:
aws configure
- Enter the Access Key ID and Secret Access Key when prompted.
- Specify the default region (e.g.,
us-west-1
). This should be the region where you will deploy the resources.
Setting Up The Infrastructure With Terraform
With the AWS CLI configured, the next step is to set up the actual lab infrastructure using Terraform. Terraform will allow you to automate the deployment of all required AWS resources.
Clone The Infrastructure Setup Scripts
- Open your terminal.
- Run the following command to clone the lab infrastructure setup repository. This repository contains all the necessary Terraform scripts for various lab topics.
git clone https://github.com/open-devsecops/lab-infra-setup.git
- Change into the directory containing the Terraform scripts for Topic 3 DevOps lab:
cd lab-infra-setup/topic-2-devops/aws
Initialize Terraform
- Within the Topic 2 - DevOps directory, initialize Terraform to install necessary providers and set up your environment.
- In the terminal, enter the following:
terraform init
- Before applying any changes, review what Terraform intends to do. This command will show you a list of resources that Terraform plans to create.
terraform plan
- Apply the configuration to begin provisioning the AWS resources.
terraform apply
-
When prompted to
Enter a value:
, enteryes
. - After Terraform successfully applies the configuration, it will output important information such as public IPs, or other commands and other data needed to access your resources.
Output Name | Description | Usage |
---|---|---|
SSH | SSH command to access the EC2 instance. | Use this command to SSH into the EC2 instance for administrative tasks or troubleshooting. |
ec2_public_ip | The public IP address of the EC2 instance. | Needed to access various web interfaces for the lab, such as downloading VPN configurations, accessing Jenkins, etc. |
Please allow sufficient time for tools to install. After Terraform successfully provisions the AWS resources, it typically takes about 5 minutes for all software tools to be fully installed and operational on the provisioned resources. You can verify completion by entering in the terminal [ssh command] -f "grep 'Lab Infrastructure Provisioning Complete' /var/log/cloud-init-output.log"
.
Example Output
aws_subnet.lab_public_subnet: Creation complete after 1s
aws_route_table.lab_public_route_table: Creation complete after 1s
aws_route_table_association.lab_pub_sub_rt: Creating...
aws_route_table_association.lab_pub_sub_rt: Creation complete after 1s
aws_security_group.lab: Creation complete after 2s
aws_instance.topic-2-lab: Creating...
aws_instance.topic-2-lab: Still creating... [10s elapsed]
aws_instance.topic-2-lab: Creation complete after 13s
Apply complete! Resources: 16 added, 0 changed, 0 destroyed.
Outputs:
SSH = "ssh -i topic-2-cicd-lab-key.pem ubuntu@54.176.55.245"
ec2_public_ip = "54.176.55.245"
Accessing Internal Services
Use The VPN Config Generator
- Navigate to the VPN Config Generator at
https://{ec2_public_ip}
. Replace{ec2_public_ip}
with the actual public IP address output by Terraform. - Download the VPN Configuration file
- Import the VPN Configuration file into your WireGuard client.
- Activate the VPN connection using WireGuard to securely connect to the internal network.
- Access internal services such as
http://dashboard.internal
orhttp://jenkins.internal
.
Configuring Jenkins
Once your infrastructure is ready and you have connected to the internal network via VPN, you can proceed to set up Jenkins for the DevOps labs.
- Navigate to
http://jenkins.internal
in your web browser. - To unlock Jenkins and begin setup, you need the initial admin password. Use the command below to retrieve this.
ssh -i topic-2-cicd-lab-key.pem ubuntu@{ec2_public_ip} -f "sudo docker exec jenkins cat /var/jenkins_home/secrets/initialAdminPassword"
Make sure you are in the topic-2-devsecops/aws
directory where the SSH key is located before you enter the command.
-
Back in your web browser on the Jenkins unlock page, enter the initial admin password you retrieved to unlock
-
Select the option to Install suggested plugins.
- Once the plugin installation is complete, proceed to the Create First Admin User step.
- Fill out the form with the admin username, password.
- On the Instance Configuration page, ensure the Jenkins URL is set to http://jenkins.internal/. This should be populated automatically.
- Click Save and Finish.
Setting Up Jenkins
Creating Student Account
Finally, let’s set up a student account that has the necessary permissions to create and manage pipelines but does not possess full administrative rights.
- Click on Manage Jenkins from the main menu on the left.
- Access
Security > Users
- Click on Create User to set up a new account.
- Return to Manage Jenkins and select
Security > Security
. - Scroll to the Authorization section.
- Select “Matrix-based security” from the list of Authorization strategies.
- Click Add user.
- Enter the username of the student account you created.
- Configure the permissions for the student account as follows and click on “Save” to apply the changes.
(Optional) Installing BlueOcean Plugin
BlueOcean improves the user experience of Jenkins, providing a more visual and intuitive approach to pipeline creation and management.
- Go back to the Manage Jenkins page and select Manage Plugins.
- Switch to the Available tab and use the search bar to find
Blue Ocean
. - Check the box next to Blue Ocean
- Click on Install to begin installing the selected plugins.