This Terraform project provisions an AWS EC2 instance with a web server that serves a custom HTML page.
This project creates:
- An AWS EC2 instance (t3.micro) running Amazon Linux
- A security group allowing HTTP (port 80) and SSH (port 22) access
- An Apache web server (httpd) configured to serve a custom HTML page
- An SSH key pair for secure instance access
Before running this project, ensure you have:
-
Terraform installed (version >= 1.5.0)
terraform --version
-
AWS CLI configured with valid credentials
aws configure
-
SSH Key Pair generated at
~/.ssh/terraform_key.pubssh-keygen -t rsa -b 4096 -f ~/.ssh/terraform_key -
AWS Account with appropriate permissions to create EC2 instances, security groups, and key pairs
.
├── main.tf # Main infrastructure configuration
├── terraform.tf # Provider and version requirements
├── hello.html # Custom HTML page served by the web server
├── terraform.tfstate # Terraform state file (auto-generated)
└── README.md # This file
Initialize the Terraform working directory and download required providers:
terraform initPreview the resources that will be created:
terraform planCreate the infrastructure:
terraform applyType yes when prompted to confirm.
After successful deployment, Terraform will output the instance details. You can find the public IP in the AWS Console or by running:
terraform show | grep public_ipVisit http://<public-ip> in your browser to see your web page.
Connect to your instance via SSH:
ssh -i ~/.ssh/terraform_key ec2-user@<public-ip>- AWS Region:
ap-southeast-3(Jakarta) - To change the region, edit the
regionvalue interraform.tf
- AMI ID:
ami-0559665adb3f0e333 - This is an Amazon Linux AMI for the ap-southeast-3 region
- Type:
t3.micro(1 vCPU, 1 GB RAM) - Free tier eligible
- Inbound:
- Port 80 (HTTP) from anywhere (0.0.0.0/0)
- Port 22 (SSH) from anywhere (0.0.0.0/0)
- Outbound:
- All traffic allowed
To destroy all resources created by this project:
terraform destroyType yes when prompted to confirm.
Contains the main infrastructure resources:
aws_security_group.web_sg- Security group configurationaws_key_pair.terraform_key- SSH key pairaws_instance.web- EC2 instance with user data script
Defines:
- Required Terraform version (>= 1.5.0)
- AWS provider configuration (version ~> 5.0)
- AWS region setting
Custom HTML page that gets deployed to the web server at /var/www/html/index.html
- Ensure AWS CLI is configured:
aws configure - Check that your AWS credentials are valid
- Verify that the SSH key exists at
~/.ssh/terraform_key.pub - Ensure the key has proper permissions
- Wait 2-3 minutes after deployment for user data script to complete
- Check security group rules allow HTTP traffic
- Verify instance is in "running" state in AWS Console
This project is provided as-is for educational and demonstration purposes.