Browse the Repo

file-type-icon.circleci
file-type-icon.github
file-type-iconexamples
file-type-iconasg-instance-refresh-with-launch-template
file-type-iconasg-instance-refresh
file-type-iconwith-elb
file-type-iconwithout-elb
file-type-iconREADME.md
file-type-iconasg-rolling-deploy
file-type-iconserver-group
file-type-iconmodules
file-type-icontest
file-type-icon.gitignore
file-type-icon.pre-commit-config.yaml
file-type-iconCODEOWNERS
file-type-iconCONTRIBUTING.md
file-type-iconLICENSE.txt
file-type-iconREADME.md
file-type-iconterraform-cloud-enterprise-private-module-...

Browse the Repo

file-type-icon.circleci
file-type-icon.github
file-type-iconexamples
file-type-iconasg-instance-refresh-with-launch-template
file-type-iconasg-instance-refresh
file-type-iconwith-elb
file-type-iconwithout-elb
file-type-iconREADME.md
file-type-iconasg-rolling-deploy
file-type-iconserver-group
file-type-iconmodules
file-type-icontest
file-type-icon.gitignore
file-type-icon.pre-commit-config.yaml
file-type-iconCODEOWNERS
file-type-iconCONTRIBUTING.md
file-type-iconLICENSE.txt
file-type-iconREADME.md
file-type-iconterraform-cloud-enterprise-private-module-...
Auto Scaling Group (stateless)

Auto Scaling Group (stateless)

Run an Auto Scaling Group for stateless apps. Supports zero-downtime, rolling deployment, auto healing, auto scaling, and IAM Roles.

Code Preview

Preview the Code

mobile file icon

README.md

down

Auto Scaling Group with Instance Refresh Examples

This folder shows examples of how to use the asg-instance-refresh module to create an Auto Scaling Group (ASG) that supports rolling deployment via instance refresh:

  • with-elb: An example of how to deploy an ASG where each instance registers with an Elastic Load Balancer (ELB).
  • without-elb: An example of how to deploy an ASG without any load balancer.

On each EC2 Instance in the ASG, for demonstration and testing purposes, we run a dummy web server that just returns "Hello World". If you update this app (e.g. change the text to "Hello, World v2" or replace the app with a totally different AMI of your own), the next time you run terraform apply, the new version of the app will roll out automatically, with no downtime, across your ASG.

How do you run these examples?

  1. Install Terraform.
  2. Open variables.tf, set the environment variables specified at the top of the file, and fill in any other variables that don't have a default.
  3. Run terraform get.
  4. Run terraform plan.
  5. If the plan looks good, run terraform apply.

Deploying a new version

Once you have the app up and running, to test out the rolling deployment, make a change to any of the variables passed into the ASG. For example, as a quick test, you could change the server_text variable to "Hello, World, v2.0!". Once you've made your changes, do the following:

  1. Commit your changes to Git so your teammates have access to them.
  2. Run terraform plan.
  3. If the plan looks good, run terraform apply.

The new version of the app will automatically deploy across the Auto Scaling Cluster. This is accomplished by taking advantage of AWS's Instance Refresh via the Terraform instance_refresh resource, which allows the Auto Scaling Group to perform a rolling replacement of all running instances based on completion of instance warmup, passing of health checks, and completion of checkpoints.

Questions? Ask away.

We're here to talk about our services, answer any questions, give advice, or just to chat.

Ready to hand off the Gruntwork?