This project sets up two Nginx web servers and an HAProxy load balancer using Terraform and Ansible. The load balancer distributes incoming requests to the two Nginx servers in a round-robin fashion.
- Terraform installed
- Ansible installed.
- AWS CLI configured with valid AWS credentials.
- Clone this repository and navigate to the root directory.
- Run terraform init and terraform apply in the infrastructure/terraform folder to create the AWS instances.
- Terraform local exec will populate hosts.ini with the instance ip-s
- Run ansible-playbook -i ansible/hosts.ini ansible/site.yml to configure the instances with HAProxy and Nginx.
- Navigate to the public IP address of the HAProxy instance in a web browser.
- Refresh the page a few times to see the load balancer distribute the requests to the two Nginx servers.
- Run terraform destroy in the infrastructure/terraform folder to destroy the AWS instances.
.
├── ansible
│ ├── ansible.cfg
│ ├── hosts.ini
│ ├── new_key
│ ├── new_key.pub
│ ├── pwd.txt
│ ├── roles
│ │ ├── haproxy
│ │ │ ├── handlers
│ │ │ │ └── main.yml
│ │ │ ├── tasks
│ │ │ │ └── main.yml
│ │ │ └── templates
│ │ │ └── haproxy.cfg
│ │ └── nginx
│ │ ├── handlers
│ │ │ └── main.yml
│ │ ├── tasks
│ │ │ └── main.yml
│ │ └── templates
│ │ └── nginx.conf
│ ├── site.yml
│ └── vault.yml
├── readme.md
└── terraform
├── main.tf
├── new-key.pem
├── outputs.tf
├── terraform.tfstate
├── terraform.tfstate.backup
└── variables.tf