This Terraform configuration sets up a basic AWS infrastructure with an EC2 instance, an Internet Gateway, a route table, and security group rules.
- Terraform installed (Download)
- AWS CLI installed and configured with an IAM user (Guide)
- AWS credentials profile set up (
~/.aws/credentials
)
- Attaches an Internet Gateway to the specified VPC.
- Creates a public route table to allow internet access.
- Deploys an EC2 instance within the specified subnet.
- Assigns a public IP to the instance.
- Associates the instance with a security group.
- Ingress Rules:
- Allow HTTP traffic (ports 80-100) from all sources.
- Plan to allow HTTPS traffic (port 443) from all sources.
- Allow SSH access (port 22) from all sources.
- Egress Rules:
- Allow all outbound traffic.
The following variables should be defined in a terraform.tfvars
file or passed via CLI:
vpc_id = "your-vpc-id"
subnet = "your-subnet-id"
profile-id = "your-aws-profile"
ami = "your-ami-id"
instance_type = "t2.micro"
- Initialize Terraform
terraform init
- Plan the deployment
terraform plan
- Apply the configuration
terraform apply -auto-approve
- Destroy the infrastructure (if needed)
terraform destroy -auto-approve
This project includes a custom Python script to create PostgreSQL database backups and upload them to Amazon S3 for secure, durable storage.
To run the backup manually, execute the following command in your terminal:
PGPASSWORD='your_password' python3 backup/backup_to_s3.py
- Ensure that the provided
vpc_id
andsubnet
exist within your AWS account. - Modify the security group settings as needed for your use case.
Check out my YouTube video where I explain my thoughts on this Terraform setup: Watch Here
This project is licensed under the MIT License.