Automated EC2 Web Server Deployment Using Terraform

Terraform

Project Overview:

In this project, I used Terraform to Provision an Amazon EC2 instnace and automatically configure it as a web server runing Nginx. The infrastructure and configuration were fully automated using infrastructure as Code (Iac)principles.

Architecture Overview

- infrastructure as Code (Iac)
- Automate server configuration
- Use Terraform provisioners (remote-exec and local-exec)
- Secure SSH access using key pairs
- Automated software installation
- Basic DevOps automation practices

Technologies Used

- AWS EC2
- Terraform
- Nginx
- SSh
-Amazon Linux

Steps taken to complets this project :

1. Defined AWS infrastructure with Terraform

Terraform
Terraform
Terraform
Terraform
Terraform

- Configured the AWS provider
- Defined an EC2 instance resource
- Attached a security group allowing: Port 22(SSH) and Port 80(HTTP)


2. Created and Used an SSH key pair

Terraform

- Referenced an existing SSH key pair
- Associated the key pair with the EC2 instance
- Used the private key for secure remote access


3. Installed and Configured Nginx

Terraform
Terraform
Terraform

Used the remote-exec provisioner to:
- Connect to the EC2 instance via SSH.
- Update the system packages.
- Install Nginx
- Start and enabled the Nginx service

This ensured the web server was configured immediately after provisioning


4. Executed Local Commands Using local-exec

Terraform
Terraform

Used the local-exec provisioner to:
- Output the public IP address.
- Display deployment confirmation messages.
- Assist with post deployment verification.

5.Verified Deployment

Amazon EC2
Nginx
Nginx
Nginx

- Accessed the EC2 public_IP address in browser.
- Confirmed that the Nginx default page was displayed
- Verified successful automation from provisioning to application setup

6. Destroyed AWS Resources Using Terraform

Terraform
Terraform
Terraform

- Executed terraform destroy
- Used local-exec provisioner to display destroy confirmation message
Terraform:
- Terminated the EC2 instance
- Removed the security group
- Cleaned up all associated resources