This project demonstrates how to create and manage infrastructure using Terraform and automate the deployment process using GitHub Actions as CI/CD.
This repository provides a modular approach to creating AWS resources such as:
- Application Load Balancer
- Security Groups
- EC2 Instances
- VPC
The deployment process is fully automated using GitHub Actions, triggered on every push to the main
branch.
- VPC Module: Creates a Virtual Private Cloud.
- Security Groups Module: Manages security groups.
- EC2 Module: Provisions EC2 instances.
- Application Load Balancer Module: Sets up an ALB.
We use AWS S3 to store the Terraform state files remotely, enabling team collaboration and state locking.
The GitHub Actions workflow is defined in .github/workflows/deploy.yml
and includes the following steps:
- Checkout Code: Checks out the repository code.
- Set up Terraform: Installs Terraform.
- Initialize Terraform: Initializes Terraform configuration.
- Validate Terraform: Validates the Terraform configuration.
- Apply Terraform: Applies the Terraform configuration to provision resources.
- Destroy Terraform: Destroys the infrastructure (commented out).
Prerequisites
- Terraform installed
- AWS CLI configured with appropriate credentials
- GitHub repository with Secrets for AWS credentials
- Installation
- Clone the repository:
git clone https://github.com/parvez76/terraform-with-github-actions
cd iaac
terraform init
Deploy Infrastructure: Push your changes to the main branch to trigger the GitHub Actions workflow:
git add .
git commit -m "Deploy infrastructure"
git push origin main
Destroy Infrastructure: To destroy the infrastructure, uncomment the Terraform Apply section in the workflow and comment out the Terraform Destroy section, then push the changes.