100 Days of DevOps — Day 20— Auto-Scaling Group using Terraform

Welcome to Day 20 of 100 Days of DevOps, Let continue our terraform journey, yesterday we created an application load balancer, let expand that concept and put this load balancer as a part of the auto-scaling group.

  • We can specify a minimum number of instances and AWS EC2 Auto Scaling ensures that your group never goes below this size.
  • The same way we can specify the maximum number of instances and AWS EC2 Auto Scaling ensures that your group never goes above this size.
  • If we specify the desired capacity, AWS EC2 Auto Scaling ensures that your group has this many instances.
  • Configuration templates(launch template or launch configuration): Specify Information such as AMI ID, instance type, key pair, security group
  • If we specify scaling policies then AWS EC2 Auto Scaling can launch or terminate instances as demand on your application increased or decreased. For eg: We can configure a group to scale based on the occurrence of specified conditions(dynamic scaling) or on a schedule.
  • Desired Capacity of two instances.
  • The maximum size of four instances.
  • Scaling policies we define adjust the minimum or a maximum number of instances based on the criteria we specify.
  • The catch with the create_before_destroy the parameter is that if you set it to true on resource X, you also have to set it to true on every resource that X depends on (if you forget, you’ll get errors about cyclical dependencies). In the case of the launch configuration, that means you need to set create_before_destroy to true on the security group
  • This autoscaling group will spin a minimum of 1 instance and a maximum of 2 instances OR completely based on your requirement.
  • It’s going to use the launch configuration we created in the earlier step.
  • We are using an aws_availibity_zone resource which will make sure instance will be deployed in different Availability Zone.
  • A list of aws_alb_target_group ARNs, for use with Application Load Balancing, this is created During Day 19 when we created Application Load Balancer. If you are still not sure about the Value, in the outputs.tf file put this entry
output "target_group_arn" {
value = "${aws_lb_target_group.my-alb-tg.arn}"
}
Outputs:target_group_arn = arn:aws:elasticloadbalancing:us-west-2:XXXXXX0:targetgroup/my-alb-tg/85a23209f9c37964

AWS Community Builder, Ex-Redhat, Author, Blogger, YouTuber, RHCA, RHCDS, RHCE, Docker Certified,4XAWS, CCNA, MCP, Certified Jenkins, Terraform Certified, 1XGCP