This repository contains Terraform scripts for setting up a network load balancer. The scripts are designed to help you quickly deploy a network load balancer within your cloud environment, using best practices for high availability and performance. Besides a network load balancer, this repository also contains scripts for creating the following resources:
- a vpc with 2 public subnets + a route table and an internet gateway
- a launch template with a hard coded ami identifier which uses a bash script to launch a python web server listening for incoming requests on port 8080
- a security group which allows access to port 8080
- an autoscaling group which uses the launch template to deploy 2 ec2 instances in each public subnet
- a target group for the network load balancer. Instances in the autoscaling group are registered as targets
- a network load balancer that distributes traffic across instances in the target group. It specifies the subnets for the NLB.
Before you begin using these scripts, make sure you have the following:
- Terraform installed on your local machine. You can download it from the Terraform website.
- An AWS account with the necessary permissions to create network load balancers, and other related resources.
- AWS CLI configured on your machine. See the AWS CLI documentation for installation and configuration instructions.
- VPC Creation: The
vpc
module initializes a VPC where all the resources will be deployed. - Security Group Setup: The
security-group
module creates a security group within the VPC, which is later used by the launch template for EC2 instances. - Launch Template Configuration: The
launch-template
module defines the configuration for EC2 instances, including the AMI, instance type, and associated security group. - Autoscaling Group Deployment: The
autoscaling-group
module uses the launch template to create an autoscaling group. It ensures that the instances are spread across multiple subnets for high availability and registers them with the target group. - Target Group Creation: The
target-group
module creates a target group for the NLB to route traffic to. It is associated with the VPC. - Network Load Balancer Setup: Finally, the
network-load-balancer
module deploys an NLB in the specified subnets. It routes incoming traffic to the instances in the target group based on the configuration.
This setup provides a scalable and highly available infrastructure on AWS, leveraging a network load balancer to efficiently distribute traffic.
To use these Terraform scripts, follow these steps:
-
Clone the Repository:
git clone https://github.com/PetreVane/tf-scripts.git cd tf-scripts/network-load-balancer
-
Initialize Terraform:
terraform init
-
Create a Terraform Plan:
terraform plan
-
Apply the Terraform Configuration:
terraform apply
Contributions to this project are welcome! Here's how you can contribute:
- Fork the repository.
- Create a new branch for your feature (
git checkout -b feature/AmazingFeature
). - Make your changes and commit them (
git commit -m 'Add some AmazingFeature'
). - Push to the branch (
git push origin feature/AmazingFeature
). - Open a Pull Request.
For major changes, please open an issue first to discuss what you would like to change.
- Petre Vane - [email protected]
- Project Link: GitHub - PetreVane/tf-scripts