Continuing on the previous lab where I used Terraform to deploy resources, now with ALB and ASG added
Create an advanced AWS VPC spanning 2 AZs with both public and private subnets. An internet gateway and NAT gateway will be deployed into it. Public and private route tables will be established. An application load balancer (ALB) will be installed which will load balance traffic across an auto scaling group (ASG) of Nginx web servers. Security groups will be created and deployed to secure all network traffic between the various components.
├── ec2.userdata ├── main.tf ├── outputs.tf ├── terraform.tfvars └── variables.tf
- Create Terraform template to launch resources
- Create AWS environment including VPC, subnets, EC2 instance, route table, internet gateway
- Provide EC2 userdata from a separate file
- Use cidrsubnet() terraform function
- AWS account
- Terraform installed
- KeyPair in EC2 (I called my cloudacademydemo)
- Start off with initializing terraform project in your directory
- Launch the terraform environment execution by running
The main template includes creating a new VPC with 4 subnets (two public and two private), an internet gateway, elastic ip for nat gateway, route tables, security groups, application load balancer, launch template.
- Deploy the resources by running
And paste your IP for SSH connection.
Alright! Now the two webserver instances are running behind an ALB.
Navigate to the ALB’s DNS name to verify that nginx responses.
- To wrap-up run the destroy command to clean-up the environment.