This project provides a Terraform configuration to deploy a robust and cost-effective AWS infrastructure. The setup includes EC2 instances, a VPC, subnets, security groups, and an AWS Instance Scheduler to manage the lifecycle of EC2 instances.
This project aims to automate the deployment and management of AWS resources using Terraform. The infrastructure includes:
- 4 EC2 Instances:
- 2 Web Server instances are scheduled to automatically shut down every Thursday at 6 p.m. and start every Wednesday at 6 a.m. using AWS Instance Scheduler.
- 2 Database instances that remain active 24/7.
- AWS Instance Scheduler: Automates the start and stop times of the web server instances to optimize costs.
- VPC and Subnets:
- Public subnets for web server instances.
- Private subnets for database instances.
- Security Groups: Configured to allow necessary traffic.
variables.tf: Defines the variables used in the configurations.main.tf: Main Terraform configuration file.
-
Initialize Terraform:
terraform init
-
Format the Configuration:
terraform fmt
-
Validate the Configuration:
terraform validate
-
Plan the Deployment:
terraform plan
-
Apply the Deployment:
terraform apply
-
Verify Resources:
terraform show
-
Destroy the Infrastructure (when needed):
terraform destroy -auto-approve
To check the status of your EC2 instances daily:
aws ec2 describe-instances --query 'Reservations[*].Instances[*].{Instance:InstanceId,State:State.Name,Name:Tags[?Key==`Name`].Value|[0]}' --output table