Browse the Repo
Browse the Repo
Run an Auto Scaling Group for stateless apps. Supports zero-downtime, rolling deployment, auto healing, auto scaling, and IAM Roles.
This Terraform Module creates an Auto Scaling Group (ASG) that can do a zero-downtime rolling deployment. That means
every time you update your app (e.g. publish a new AMI), all you have to do is run
terraform apply and the new
version of your app will automatically roll out across your Auto Scaling Group. Note that this module only
creates the ASG and it's up to you to create all the other related resources, such as the launch configuration, ELB,
and security groups.
An Auto Scaling Group (ASG) is used to manage a cluster of EC2 Instances. It can enforce pre-defined rules about how many instances to run in the cluster, scale the number of instances up or down depending on traffic, and automatically restart instances if they go down.
Since Terraform does not have rolling deployment built in (see https://github.com/hashicorp/terraform/issues/1552), we
are faking it using the
create_before_destroy lifecycle property. This approach is based on the rolling deploy
strategy used by HashiCorp itself, as described by Paul Hinze
here. As a result, every time you
update your launch configuration (e.g. by specifying a new AMI to deploy), Terraform will:
Note that if all we did was use
create_before_destroy, on each redeploy, our ASG would reset to its hard-coded
desired_capacity, losing the capacity changes from auto scaling policies. We solve this problem by using an
external data source that runs the Python script
get-desired-capacity.py to fetch the latest value of the
If the script finds a value from an already-existing ASG, we use it, to ensure that the changes form auto scaling events are not lost.
If the script doesn't find an already-existing ASG, that means this is the first deploy, and we fall back to the
Check out the asg-rolling-deploy examples.
We're here to talk about our services, answer any questions, give advice, or just to chat.