This demonstration highlights high availability through the creation of key AWS components using Terraform: a VPC with public subnets, an Internet Gateway, and a route table. It includes setting up key pairs, security groups, a target group, EC2 instances, and an Elastic Load Balancer for efficient traffic distribution. This example performs the following steps:
- Provision a VPC.
- Create and attach an Internet Gateway to the VPC.
- Set up a route table within the VPC.
- Create two public subnets in separate availability zones within the VPC.
- Associate both subnets with the route table.
- Configure a security group that permits HTTP and SSH traffic for EC2 instances (EC2 Security Group).
- Launch EC2 instances in each public subnet.
- Associate the security group with the EC2 instances to allow HTTP and SSH traffic.
- Establish a target group and register both EC2 instances with it.
- Create a security group for the Elastic Load Balancer, permitting HTTP traffic.
- Deploy the Elastic Load Balancer using Terraform.
- Configure inbound rules to allow traffic from the Load Balancer to the EC2 Security Group.
- Generate a key pair on AWS for accessing the EC2 instances.
- Provision the EC2 instances using the web.sh script, which installs the httpd service on Ubuntu, creates an index.html file in the var/www/html directory, and writes instance metadata to the index.html.
- Create a folder named keys on the root of the folder.
- Generate 2 keys namely web01key and web02key using ssh-keygen.
- Put them in the keys folder.
- Setup AWS CLI.
- Generate keys on AWS to use with AWS CLI.
- Install terraform.
Run these commands from the root directory of the project
terraform init
terraform validate
terraform plan
terraform apply
To enhance the security of our network, we can add private subnets and move our EC2 instances into these subnets. However, since instances in private subnets are not directly accessible from the internet, it is necessary to create a NAT Gateway to enable outbound internet access.
Utilizing auto-scaling groups to launch instances adds scalability to the network, automatically adjusting resources based on demand. This approach enhances performance, maintains availability, and optimizes cost efficiency by scaling up or down as needed.
If you encounter an issue or have suggestions for improving this project, please submit an issue via the "Issues" tab above.