This project demonstrates the setup of a basic infrastructure using Terraform creating two EC2 servers and configuring them using Ansible for different purposes.
-
Instance 1: Jenkins, Ansible, and Terraform
- Jenkins: Automation server for continuous integration and continuous delivery (CI/CD).
- Ansible: Configuration management tool for automating provisioning and application deployment.
- Terraform: Infrastructure as Code tool for defining and provisioning infrastructure.
-
Instance 2: Docker with Nginx Container
- Docker: Containerization platform for packaging and running applications.
- Nginx: Web server running inside a Docker container.
- Terraform
- Ansible
- Duckdns account for the Jenkins server and deployment Domains
- Generate keypair using
ssh-keygen -t rsa -b 4096 - Ensure AWS CLI is configured with IAM access (see "Configure AWS CLI with IAM Access" section).
Before applying the Terraform configuration, ensure that your AWS CLI is configured with the necessary IAM access. If you haven't done this yet, follow these steps:
-
Install AWS CLI: Follow the instructions at AWS CLI Installation Guide.
-
Configure AWS CLI with your IAM credentials:
Open your terminal and run the following command:
aws configure
Step 0: Clone the repository
git clone https://github.com/YahyaLafdi/terraform-project.git
Step 1: Navigate to the project directory
cd terraform-project
Step 2: Create DuckDns account and domains and update modules/ec2_modules/variables with token and domain names
Step 3: Provision and configure your servers
terraform apply --auto-approve
Step 4: access jenkins and configure your pipeline (everything is in the output)
http://public-ip:8080/ OR
http://{domain-name}.duckdns.org:8080/
you can find the init password at ~/password/jenkinspassword Or in the output :
Step 5: run the jenkins pipeline
terraform destroy --auto-approve
- i have moved the statefile to an object storing in our case s3
- I have used backend
.tffile to enable remote storing and use of the.tfstatefile remotly and not locally - also i created a DynamoDB resource to use for locking the state file to prevent concurrent modification of the infrastructre.
- create you s3 Bucket and replace the name and Region in the
backend.tffile
you should avoid storing the state file in the VCS as it may discolse information regarding the Inrastructure (access keys , private keys , passwords ....) instead use Remote object storage with proper permissions

