This repository contains Terraform configurations to set up a DevOps-ready infrastructure on AWS. The setup includes a VPC, subnets, security groups, key pairs, and EC2 instances pre-configured for Jenkins, SonarQube, and Tomcat. Additionally, the configurations support Datadog integration for monitoring. This setup is designed to allow developers to deploy and manage DevOps tools seamlessly in a secure and scalable environment.
- Custom VPC: A dedicated VPC with DNS support and hostname resolution enabled.
- Subnet: A public subnet for hosting instances with internet access.
- Security Groups: Fine-grained access control for services like SSH, Jenkins, SonarQube, Tomcat, and monitoring tools such as Datadog.
- Key Pair: Secure SSH access with a pre-configured key pair.
- Internet Gateway and Route Table: Seamless internet connectivity pfor resources in the public subnet.
- Dynamic Role-Based Instance Configuration: Automatically provisions EC2 instances with role-specific configurations using custom scripts.
- Datadog Integration: Supports monitoring of instances with Datadog agents.
- AWS Account: Ensure you have an active AWS account.
- Terraform Installed: Install Terraform (>= 1.0.0) on your local machine.
- AWS CLI Configured: Configure the AWS CLI with appropriate access credentials.
- SSH Key Pair: Generate an SSH key pair named
devops_keyand place the public key at~/.ssh/devops_key.pem.pub. - Datadog API Key: Obtain a valid API key for Datadog.
git clone https://github.com/jerryben/aws-instances-bootstrapping.git
cd your-repoCreate a terraform.tfvars file in the root directory and populate it with your variables:
region = "us-east-1" # Replace with your desired AWS region
ami_id = "ami-0abcdef1234567890" # Replace with your AMI ID
instance_type = "t2.medium" # Replace with your desired instance type
datadog_api_key = "your-datadog-api-key" # Replace with your Datadog API keyRun the following command to download the required provider plugins:
terraform initReview the resources that will be created by Terraform:
terraform planProvision the infrastructure:
terraform apply.
├── main.tf # Core Terraform configurations
├── variables.tf # Input variables for the project
├── outputs.tf # Outputs for accessing deployed resources
├── scripts/ # User data scripts for configuring instances
│ ├── jenkins.sh # Jenkins setup script
│ ├── sonarqube.sh # SonarQube setup script
│ └── tomcat.sh # Tomcat setup script
├── terraform.tfvars # Variable values (not included in the repo for security)
└── README.md # Project documentation
Note that in real cases, the source here must be limited to an IP or a IP range.
| Protocol | Port Range | Purpose | Source |
|---|---|---|---|
| TCP | 22 | SSH Access | 0.0.0.0/0 |
| TCP | 80 | HTTP (Web Access) | 0.0.0.0/0 |
| TCP | 443 | HTTPS (Secure Web) | 0.0.0.0/0 |
| TCP | 8080 | Jenkins Access | 0.0.0.0/0 |
| TCP | 9090 | Cockpit Access | 0.0.0.0/0 |
| UDP | 8125 | Datadog Metrics | 0.0.0.0/0 |
| Protocol | Port Range | Purpose | Destination |
|---|---|---|---|
| All | All | Internet Access | 0.0.0.0/0 |
The scripts/ directory contains user data scripts for provisioning each EC2 instance:
- jenkins.sh: Installs Jenkins and required dependencies.
- sonarqube.sh: Installs SonarQube and sets up its environment.
- tomcat.sh: Deploys Tomcat and configures it for web applications.
#!/bin/bash
apt-get update && apt-get install -y openjdk-11-jdk jenkins
systemctl enable jenkins && systemctl start jenkinsAfter applying the Terraform configuration, you can view the outputs:
- VPC ID: The ID of the created VPC.
- Subnet ID: The ID of the created subnet.
- Instance Public IPs: The public IPs of the provisioned instances.
To destroy the created infrastructure:
terraform destroy- Add support for additional roles and tools (e.g., Nexus, Prometheus).
- Automate backups for persistent volumes.
- Introduce scaling policies for instances.
This project is licensed under the MIT License.
Contributions are welcome! Please fork this repository and create a pull request for any feature enhancements or bug fixes.