Skip to content

MHS-4ever/project-06-terraform-aws

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Project 6 — Infrastructure as Code with Terraform (AWS)

Provisioning AWS Infrastructure Using Terraform


📌 Project Overview

This project demonstrates the use of Terraform to provision and manage AWS infrastructure using Infrastructure as Code (IaC) principles.

Instead of creating resources manually through the AWS Console, all infrastructure components were defined declaratively and deployed in a repeatable, automated way. The project focuses on correctness, security, and clean lifecycle management — including safe teardown to avoid unnecessary costs.


🎯 Objectives

  • Use Terraform to provision AWS infrastructure
  • Configure AWS provider securely using IAM (not root)
  • Create an EC2 instance and security group via code
  • Restrict SSH access using CIDR-based rules
  • Output useful infrastructure information
  • Safely destroy infrastructure after verification
  • Follow Free Tier–friendly and cost-aware practices

📋 Prerequisites

  • Terraform installed (v1.0+)
  • AWS Account with programmatic access
  • AWS CLI configured with IAM credentials
  • EC2 Key Pair created in target region
  • Basic knowledge of Terraform HCL syntax

🚀 Quick Start

1. Configure AWS Credentials

aws configure
# Enter your AWS Access Key ID, Secret Access Key, Region, and Output format

2. Initialize Terraform

terraform init

3. Review Execution Plan

terraform plan

4. Apply Infrastructure

terraform apply -var="key_name=YOUR_KEY_NAME" -var="ssh_cidr=YOUR_PUBLIC_IP/32"

5. Access EC2 Instance

# Get instance public IP from outputs
terraform output instance_public_ip

# SSH into instance
ssh -i your-key.pem ubuntu@$(terraform output -raw instance_public_ip)

6. Destroy Infrastructure

terraform destroy

🧩 Architecture

flowchart TB
    Dev[Developer Laptop]
    TF[Terraform CLI]
    AWS[AWS Account]
    EC2[EC2 Instance<br/>Ubuntu 22.04]
    SG[Security Group<br/>SSH + HTTP]

    Dev --> TF
    TF --> AWS
    AWS --> EC2
    AWS --> SG
    SG --> EC2
Loading

🛠️ Tech Stack

  • IaC Tool: Terraform
  • Cloud Provider: AWS
  • Compute: Amazon EC2 (t2.micro – Free Tier)
  • OS: Ubuntu 22.04 LTS
  • Security: AWS Security Groups, SSH key-based access
  • Authentication: IAM User + AWS CLI credentials

🚀 Infrastructure Components

🔹 EC2 Instance

  • Ubuntu 22.04 (latest AMI)
  • Free Tier eligible instance type
  • SSH access via EC2 Key Pair
  • Public IP assigned dynamically

🔹 Security Group

  • SSH (22) restricted to developer's public IP
  • HTTP (80) open for web traffic
  • All outbound traffic allowed

🔐 Security Practices

  • AWS root user not used for Terraform
  • Dedicated IAM user with programmatic access
  • AWS credentials stored locally via aws configure
  • No secrets hardcoded in Terraform files
  • SSH access restricted by CIDR
  • Infrastructure destroyed after validation

📁 Repository Structure

project-06-terraform-aws/
├── main.tf
├── provider.tf
├── variables.tf
├── outputs.tf
├── README.md
├── .gitignore
└── architecture/
    └── terraform-aws-ec2.mmd

🧪 Verification Steps

  • ✅ Initialized Terraform (terraform init)
  • ✅ Reviewed execution plan (terraform plan)
  • ✅ Applied infrastructure (terraform apply)
  • ✅ Connected to EC2 via SSH successfully
  • ✅ Verified networking and security behavior
  • ✅ Destroyed all resources (terraform destroy)

🧹 Infrastructure Teardown

After successful validation, all AWS resources were destroyed using:

terraform destroy

This ensures:

  • No ongoing AWS costs
  • No orphaned resources
  • Clean and repeatable infrastructure lifecycle

📌 Resume Highlights

  • Provisioned AWS infrastructure using Terraform (IaC)
  • Automated EC2 and security group creation via code
  • Implemented secure IAM-based authentication
  • Debugged real-world SSH and networking issues
  • Practiced full infrastructure lifecycle management

🏷️ Tags

Terraform · AWS · EC2 · Infrastructure as Code · DevOps · Cloud Engineering

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages