This example has been created by Miha Markočič
This example deploys AWS network infrastructure (VPC and public subnet), three web servers, and a network load balancer:
- Create a new VPC (10.0.0.0/16)
- Create one public (10.0.1.0/24) subnet
- Create internet gateway and associate it with VPC
- Create a new route table and add a route towards internet gateway for public subnet traffic
- Create webserver SG (HTTP, HTTPS and SSH from anywhere; HTTP, HTTPS to anywhere)
-
Obtain AWS AMI ID for the desired os (Ubuntu Server 20.04 LTS from Canonical)
-
Deploy 3 webserver instances in a created public subnet
-
Update apt-get on each instance using "remote-exec" Terraform provisioner
-
Run Ansible playbook1 using "local-exec" Terraform provisioner to:
- Install Apache service on all 3 Ubuntu servers
- Enable Includes and cgi Apache2 modules
- Copy .htaccess file with to var/www/html/
- Enable XBitHack in apache2.conf configuration file
- Add Includes to the var/www/ directory in apache2.conf
- Replace index.html file. Replaced html homepage is set to show webserver's ifconfig.
- Restart Apache service
1 Ansible Playbook is run only once with the remote provisioner as there are all 3 webservers in the Ansible inventory. Ansible inventory uses aws_ec2 plugin.
- Deploy network load balancer with an elastic IP in a public subnet with 3 webserver instances
- Create 2 load balancer listeners listening to the incoming traffic:
- Forwarding the incoming HTTP requests on port 80
- Forwarding the incoming HTTPS requests on port 443
- Create 2 target groups (HTTP and HTTPS) to distribute the load between the targets
- Create target group attachments to attach individual instance/node to the desired target group2. In this example, all 3 instances (webserver1, webserver2, webserver3) are associated with http and https target group.
2 All targets in the same target group have to run the same service.