This project demonstrates how to use Terraform to provision and manage AWS resources, including:
- VPC: Virtual Private Cloud with subnets, internet gateway, and route tables.
- S3 Bucket: Secure S3 bucket with a bucket policy to enforce HTTPS access.
- RDS Instance: MySQL database instance with a security group and subnet group across multiple AZs.
- GitHub Actions: Automated Terraform workflow for CI/CD.
This screenshot shows the VPC created using Terraform, including subnets, route tables, and internet gateway.
This screenshot shows the S3 bucket created using Terraform, with a bucket policy enforcing HTTPS access.
This screenshot shows the MySQL RDS instance deployed across multiple Availability Zones.
This screenshot shows the successful execution of the GitHub Actions workflow for Terraform.
This Terraform project automates the deployment of a secure and scalable AWS infrastructure, including:
- VPC: A Virtual Private Cloud with public subnets.
- Subnets: Two public subnets across different availability zones.
- Internet Gateway: Enables internet access for resources in the public subnets.
- Route Table: Configures routing for the public subnets.
- S3 Bucket: A private S3 bucket with a lifecycle policy to expire objects after 90 days.
- RDS Instance: A MySQL database instance with restricted access within the VPC.
- Security Groups: Ensures secure communication between resources.
The project is designed to follow best practices for security, scalability, and maintainability.
Before using this Terraform configuration, ensure you have the following:
- Terraform Installed: Download and install Terraform from here.
- AWS CLI Configured: Set up your AWS credentials using the AWS CLI or environment variables.
- AWS Account: Ensure you have an AWS account with sufficient permissions to create the resources.
- GitHub Repository: Fork or clone this repository.
git clone https://github.com/abaasi256/terraform-aws-ec2.git
cd terraform-aws-ec2
Run the following command to initialize Terraform and download the required providers:
terraform init
Validate the Terraform configuration for syntax errors:
terraform validate
Preview the changes Terraform will make:
terraform plan
Deploy the infrastructure:
terraform apply
When you no longer need the infrastructure, destroy it to avoid unnecessary costs:
terraform destroy
This Terraform configuration creates the following AWS resources:
- VPC: A Virtual Private Cloud with a CIDR block of
10.0.0.0/16
. - Subnets: Two public subnets in different availability zones.
- Internet Gateway: Attached to the VPC for internet access.
- Route Table: Routes traffic from the public subnets to the internet gateway.
- S3 Bucket: A private bucket with a lifecycle policy to expire objects after 90 days.
- RDS Instance: A MySQL database instance with restricted access.
- Security Groups: Controls inbound and outbound traffic for the RDS instance.
The following input variables are used in this project:
Variable Name | Description | Default Value | Required |
---|---|---|---|
rds_password |
Password for the RDS database | - | Yes |
After applying the configuration, Terraform will output the following:
Output Name | Description |
---|---|
vpc_id |
ID of the created VPC |
s3_bucket_name |
Name of the created S3 bucket |
rds_endpoint |
Endpoint of the RDS instance |
public_subnet_id |
ID of the first public subnet |
public_subnet_2_id |
ID of the second public subnet |
project_author |
Author and project details |
- Secure Sensitive Data: Use Terraform's
sensitive
flag for sensitive variables like passwords. - Dynamic Availability Zones: Use AWS data sources to fetch availability zones dynamically.
- Lifecycle Policies: Configure lifecycle rules for S3 buckets to manage object expiration.
- Restrict Access: Use security groups and bucket policies to restrict access to resources.
- Tagging: Tag all resources for better identification and cost management.
- Abaasi: Project author and maintainer.
Hi, I'm Abaasi, a cloud and DevOps enthusiast passionate about automating infrastructure using Terraform. This project is a reflection of my skills and expertise in AWS and Infrastructure as Code (IaC). Connect with me on LinkedIn or check out my other projects on GitHub.
This project is licensed under the MIT License. See the LICENSE file for details.
- Terraform Documentation: https://www.terraform.io/docs
- AWS Documentation: https://docs.aws.amazon.com