Skip to content

Latest commit

Β 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“„ README.md

# πŸš€ Terraform AWS EC2 Setup with Custom VPC

This project uses Terraform to provision an EC2 instance inside a custom VPC on AWS. The instance is publicly accessible and configured to run a web server (e.g., Apache) using a user data script. It includes the creation of essential networking components like a VPC, subnet, internet gateway, route table, and security group.

---

## πŸ› οΈ Features

- βœ… Custom VPC and Subnet
- βœ… Internet Gateway and Route Table for internet access
- βœ… Security Group allowing HTTP (port 80) and SSH (port 22)
- βœ… EC2 instance with user data to bootstrap Apache
- βœ… Public IP assignment for direct access

---

## πŸ“ Project Structure

. β”œβ”€β”€ main.tf # Main Terraform configuration β”œβ”€β”€ userdata.sh # Startup script to configure Apache on EC2 └── README.md # Project documentation


---

## 🚧 Prerequisites

- [Terraform](https://developer.hashicorp.com/terraform/downloads)
- AWS account with programmatic access (access key & secret)
- IAM permissions to manage EC2, VPC, and networking
- AWS CLI (optional, for credential setup)

---

## πŸ” AWS Credentials Setup

Set your AWS credentials as environment variables:

```bash
export AWS_ACCESS_KEY_ID="your_access_key"
export AWS_SECRET_ACCESS_KEY="your_secret_key"

Alternatively, configure using the AWS CLI:

aws configure

πŸš€ How to Use

  1. Clone the Repository
git clone https://github.com/your-username/terraform-aws-ec2-vpc.git
cd terraform-aws-ec2-vpc
  1. Initialize Terraform
terraform init
  1. Preview the Plan
terraform plan
  1. Apply the Infrastructure
terraform apply
  1. Access the EC2 Instance

Once provisioning completes, Terraform will output the public IP (if configured). You can:

  • SSH into the instance
  • Open the browser and visit http://<public-ip> to view the Apache web server

πŸ“œ User Data Script

The userdata.sh file is used to automatically install and start Apache during instance launch. You can modify it to suit your server setup needs.

Example content:

#!/bin/bash
apt update -y
apt install apache2 -y
systemctl start apache2
systemctl enable apache2
echo "Hello from $(hostname)" > /var/www/html/index.html

πŸ” Teardown

To destroy all infrastructure created by this project:

terraform destroy

🧠 Notes

  • Ensure your chosen AMI ID (ami-00a929b66ed6e0de6) is valid in the us-east-1 region.
  • Public IPs are assigned via map_public_ip_on_launch = true in the subnet.
  • This project avoids using default VPCs and builds everything from scratch for clarity and control.

πŸ“ License

This project is open-source and available under the MIT License.


About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages