Welcome to the Terraform repository for deploying AWS infrastructure. This repository contains all the necessary configurations and scripts to set up and manage a robust and scalable environment using various AWS services.
- Introduction
- Architectural Design
- Prerequisites
- Installation
- Reusable Workflows
- Usage
- Configuration
- Modules
- Examples
- Testing
- Deployment
- Troubleshooting
- Contributing
- License
- Contact
This project automates the provisioning and deployment of AWS infrastructure using Terraform. The infrastructure can include:
- AWS EC2 for compute instances.
- AWS RDS for database management.
- AWS S3 for storage.
- AWS VPC for network segmentation.
- AWS IAM for access control.
- AWS Elastic Beanstalk for application deployment.
- AWS MQ for messaging.
Before you begin, ensure you have the following:
- An AWS account with appropriate permissions.
- Terraform installed on your local machine.
- AWS CLI configured with your AWS credentials.
- SSH key pair for accessing EC2 instances.
- Terraform: Infrastructure as Code (IaC) tool used for provisioning the AWS resources.
- AWS EC2: Compute instances for application servers.
- AWS RDS: Managed relational database service.
- AWS S3: Scalable storage service.
- AWS VPC: Virtual Private Cloud for network isolation.
- AWS IAM: Identity and Access Management for security.
- AWS Elastic Beanstalk: Managed service for deploying and scaling web applications.
- AWS MQ: Managed message broker service.
git clone https://github.com/yourusername/Terraform_repo.git
cd Terraform_repo
Ensure your AWS CLI is configured with the necessary credentials:
aws configure
Initialize the Terraform working directory:
terraform init
The repository includes reusable GitHub Actions workflows to streamline and automate the deployment and management of AWS infrastructure. These workflows are designed to be modular and reusable across different repositories and projects.
-
EKS Deployment Workflow
- Filename:
.github/workflows/eks.yml
- Purpose: Automates the deployment of Amazon EKS clusters.
- Usage: This workflow handles the creation and management of Kubernetes clusters in AWS, including updating kubeconfig and installing required components such as the Ingress Controller.
- Filename:
-
EBS Deployment Workflow
- Filename:
.github/workflows/beanstalk.yml
- Purpose: Manages the deployment of AWS Elastic Beanstalk applications.
- Usage: Use this workflow to deploy and manage Elastic Beanstalk environments for your applications, including configuration updates and environment management.
- Filename:
-
AWS Setup Workflow
- Filename:
.github/workflows/aws_setup.yml
- Purpose: Sets up initial AWS infrastructure and configurations.
- Usage: This workflow initializes essential AWS resources and configurations needed for other workflows or applications, such as creating IAM roles or setting up network components.
- Filename:
To leverage these workflows in your own repositories, follow these steps:
-
Reference the Workflow
In your
.github/workflows
directory, create a YAML file that calls the reusable workflow:name: Example Deployment on: push: branches: - main jobs: deploy: uses: Amits64/shared_library/.github/workflows/terraform-setup.yml@main with: aws-region: ${{ secrets.AWS_REGION }} tf-cloud-token: ${{ secrets.TF_CLOUD_TOKEN }} aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
-
Provide Required Inputs
Ensure you provide all necessary inputs for the workflow, such as AWS credentials, region, and any other required parameters. These should be configured as GitHub secrets in your repository.
-
Monitor Workflow Runs
Check the Actions tab in your GitHub repository to monitor the execution and status of the workflows. Logs and statuses will provide insights into the progress and outcomes of the workflows.
- Consistency: Ensure uniform deployment practices across different projects and repositories.
- Efficiency: Save time by reusing established workflows rather than recreating them for each project.
- Maintainability: Simplify updates and changes to workflows by centralizing them in a shared repository.
Update the variables.tf
file with your specific values, such as:
- AWS region
- VPC ID
- Subnet IDs
- Security group IDs
- Key pair name
- S3 bucket names
Generate and review the execution plan:
terraform plan
Apply the Terraform configuration to provision the resources:
terraform apply
Verify that all resources have been provisioned correctly by checking the AWS Management Console.
This repository uses a variables.tf
file to manage input variables. Key variables include:
aws_region
: The AWS region to deploy resources.vpc_id
: The ID of the VPC.public_subnets
: List of public subnet IDs.private_subnets
: List of private subnet IDs.instance_type
: The EC2 instance type.key_name
: The name of the SSH key pair.db_username
: The database username.db_password
: The database password.
Sensitive information such as database passwords and API keys should be stored in environment variables or a secrets management tool rather than hardcoded in the Terraform files.
Manages the VPC, subnets, and associated networking components.
Handles the provisioning of EC2 instances.
Manages the setup of the RDS database.
Manages S3 buckets and related configurations.
Handles the creation and management of IAM roles, policies, and users.
Automates the deployment of the Elastic Beanstalk environment.
Manages AWS MQ for messaging.
A basic example of deploying EC2 instances with minimal configuration.
module "vpc" {
source = "./modules/vpc"
...
}
module "ec2" {
source = "./modules/ec2"
...
}
A more complex example with custom IAM roles, policies, and additional security configurations.
module "vpc" {
source = "./modules/vpc"
...
}
module "ec2" {
source = "./modules/ec2"
...
}
resource "aws_iam_role" "example" {
...
}
Validate the syntax of the Terraform files:
terraform validate
Generate the execution plan to ensure there are no errors:
terraform plan
Deploy the configuration in a non-production environment to test.
Once tested, apply the configuration to the production environment:
terraform apply -var 'environment=prod'
Monitor the resources and application using AWS CloudWatch and other relevant AWS monitoring services.
- Error: Subnet not found: Ensure the subnet IDs are correct and exist in your VPC.
- Permission Denied: Verify IAM roles and policies have the necessary permissions.
Check the logs in AWS services such as CloudWatch, Elastic Beanstalk, and RDS for detailed error messages.
- Fork the repository.
- Create a staging branch (
git checkout -b staging
). - Commit your changes (
git commit -m 'Add some changes'
). - Push to the branch (
git push origin staging
). - Create a new Pull Request.
Please adhere to the Contributor Covenant Code of Conduct.
This project is licensed under the MIT License. See the LICENSE file for details.
For any questions or support, please reach out to:
- Name: Amit Singh
- Email: chauhanamit090@hotmail.com
- LinkedIn: Amit Singh