Skip to content

This repo demonstrates how to create ALB and ASG. Terraform configurations here are for learning purpose only.

Notifications You must be signed in to change notification settings

shazChaudhry/terraform_aws_alb_asg

Repository files navigation

Inspiration

Inspiration for this repo was a couple of YouTube tutorials from Java Home Cloud where it was demonstrated how to create AWS Application Load Balancers and Auto Scaling groups.

Java Home Cloud - AWS Application Load Balancer Java Home Cloud - AWS Auto Scaling group

Assumption

This is not a beginner's guide to learning Terraform or AWS. It is assumed the reader is already familier with these technologies and would instead like to find related topics like ASG and LB in one place for reference purpose.

Scope

I wanted to take a step further and automate the video instructions. The idea is that setting up of the infrastructure should be automated without human intervention.

This includes using Terraform Registry modules for creating:

  • Virtual Private Cloud (VPC) that host the entire infrastructure in this repo.
  • VPC is subdivided in four subnets; two are public and two are private
  • Application Load Balancer (ALB) in public subnets
  • Network Load Balancer (NLB) in public subnets
    • Code has been written but commented out for the following reasons:
      • NLB target groups appear to delete ALB target groups
      • For NLB to work alongside ALB, ASG security will need to be open from the entire world e.g. 0.0.0.0/0. And so, I did not want to open security group so widely
  • Classic ELB (ELB) in public subnets
  • Auto Scaling Group (ASG) in private subnets and are only reachable via LB on port 80
  • Auto Scaling policies for scaling up / down instances based on CloudWatch CPU alarms raised
  • Security groups that only allow traffic on port 80 to EC2 instances via LB

Create infrastructure

This is how infrastrucutre is setup with Terraform:

  • terraform init
  • terraform apply -auto-approve

Test

  • Classic ELB and ALB were created above. Use DNS records for each of the LB for testing.
  • Refreshing the pages should return different result depending which ASG the LB routed traffic to.

Destroy infrastructure

This is how the infrastructure created above may be destroyed if it is no longer needed

  • terraform destroy -auto-approve

Reference

About

This repo demonstrates how to create ALB and ASG. Terraform configurations here are for learning purpose only.

Topics

Resources

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published