A terraform module which provisions an auto scaling group along with its launch configuration.
This Terraform module uses another Terraform module, here is the list of Terraform module dependencies:
- the auto scaling group will have
Service
,Cluster
,Environment
, andProductDomain
tags by default, which are propagated to all instances it spawns
- To specify on-demand instance types, use the
launch_template_overrides
variable. Auto Scaling will launch instances based on the order of preference specified in that list. ["c5.large
", "c4.large
", "m5.large
"] means the ASG will always try to launchc5.large
if it's available, falling back toc4.large
if it's not available, and falling back tom5.large
if the previous two aren't available - On the first deployment, this module will provision an ASG with a launch template that select the most recent AMI that passes through the given
image_filters
- Each time there's a change in the values of the
module.asg_name
's keepers (e.g. security group, AMI ID), a new ASG will be provisioned by terraform, and the old one will later be destroyed (doing the "simple swap" deployment strategy). - When there's a change in launch template parameters' values, terraform will create a new launch template version unless the new configuration is already the same as the latest version of the launch template (e.g. when the launch template had been updated externally).
terraform init
terraform state rm module.<this module name in your terraform code>.module.random_lc
terraform apply
switching to plain launch template
module "asg" {
source = "github.com/traveloka/terraform-aws-autoscaling?ref=v0.3.1"
# ...
use_mixed_instance_policy = false
launch_template_overrides = [
{
"instance_type" = "c4.large" # this (the first element) will be the launch template's instance type
},
{
"instance_type" = "t3.medium"
},
]
}
switching to mixed instance policy
module "asg" {
source = "github.com/traveloka/terraform-aws-autoscaling?ref=v0.3.1"
# ...
use_mixed_instance_policy = true
}
This module was created on 15/08/2018. The latest stable version of Terraform which this module tested working is Terraform 0.13.7 on 28/09/2021.
Name | Version |
---|---|
terraform | >= 0.13 |
Name | Version |
---|---|
aws | n/a |
Name | Source | Version |
---|---|---|
asg_name | github.com/traveloka/terraform-aws-resource-naming.git | v0.20.0 |
launch_template_name | github.com/traveloka/terraform-aws-resource-naming.git | v0.20.0 |
Name | Type |
---|---|
aws_autoscaling_group.main | resource |
aws_launch_template.main | resource |
aws_ami.latest_service_image | data source |
Name | Description | Type | Default | Required |
---|---|---|---|---|
application | Application type that the ASG's instances will serve | string |
n/a | yes |
asg_clb_names | A list of classic load balancer names to add to the autoscaling group | list(string) |
[] |
no |
asg_default_cooldown | Time, in seconds, the minimum interval of two scaling activities | string |
"300" |
no |
asg_desired_capacity | The created ASG will have this number of instances at desired | string |
"2" |
no |
asg_enabled_metrics | The list of ASG metrics to collect | list(string) |
[ |
no |
asg_health_check_grace_period | Time, in seconds, to wait for new instances before checking their health | string |
"300" |
no |
asg_health_check_type | Controls how ASG health checking is done | string |
"ELB" |
no |
asg_lb_target_group_arns | The created ASG will be attached to this target group | list(string) |
[] |
no |
asg_max_capacity | The created ASG will have this number of instances at maximum | string |
"0" |
no |
asg_metrics_granularity | The granularity to associate with the metrics to collect | string |
"1Minute" |
no |
asg_min_capacity | The created ASG will have this number of instances at minimum | string |
"0" |
no |
asg_placement_group | The placement group for the spawned instances | string |
"" |
no |
asg_service_linked_role_arn | The ARN of the service-linked role that the ASG will use to call other AWS services | string |
"" |
no |
asg_tags | The created ASG will have these tags applied over the default ones (see main.tf) | list(map(string)) |
[] |
no |
asg_termination_policies | Specify policies that the auto scaling group should use to terminate its instances | list(string) |
[ |
no |
asg_vpc_zone_identifier | The created ASG will spawn instances to these subnet IDs | list(string) |
n/a | yes |
asg_wait_for_capacity_timeout | A maximum duration that Terraform should wait for ASG instances to be healthy before timing out | string |
n/a | yes |
asg_wait_for_elb_capacity | Terraform will wait for exactly this number of healthy instances in all attached load balancers on both create and update operations. If left to default, the value is set to asg_min_capacity | string |
"" |
no |
associate_public_ip | Whether to associate public IP to the instance | string |
"false" |
no |
cluster_role | Primary role/function of the cluster | string |
"app" |
no |
cpu_credits | The credit option for CPU usage, can be either 'standard' or 'unlimited' | string |
"unlimited" |
no |
delete_network_interface_on_termination | Whether the network interface will be deleted on termination | string |
"true" |
no |
delete_on_termination | Whether the volume should be destroyed on instance termination | string |
"true" |
no |
description | Free form description of this ASG and its instances | string |
n/a | yes |
disable_api_termination | whether to protect your instance from accidently being terminated from console or api | bool |
false |
no |
ebs_encryption | Whether the volume will be encrypted or not | string |
"false" |
no |
ebs_optimized | The spawned instances will have EBS optimization if enabled | string |
"false" |
no |
environment | The created resources will belong to this infrastructure environment | string |
n/a | yes |
image_filters | The AMI search filters. The most recent AMI that pass this filter will be deployed to the ASG. See https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-images.html | list(object({ |
n/a | yes |
image_owners | List of AMI owners to limit search. This becomes required starting terraform-provider-aws v2 (https://www.terraform.io/docs/providers/aws/guides/version-2-upgrade.html#owners-argument-now-required) | list(string) |
n/a | yes |
instance_profile_name | The spawned instances will have this IAM profile | string |
n/a | yes |
key_name | The spawned instances will have this SSH key name | string |
"" |
no |
launch_template_overrides | List of nested arguments provides the ability to specify multiple instance types. See https://www.terraform.io/docs/providers/aws/r/autoscaling_group.html#override When using plain launch template, the first element's instance_type will be used as the launch template instance type. |
list(map(string)) |
[ |
no |
mixed_instances_distribution | Specify the distribution of on-demand instances and spot instances. See https://docs.aws.amazon.com/autoscaling/ec2/APIReference/API_InstancesDistribution.html | map(string) |
{ |
no |
monitoring | The spawned instances will have enhanced monitoring if enabled | string |
"true" |
no |
product_domain | Abbreviation of the product domain this ASG and its instances belongs to | string |
n/a | yes |
security_groups | The spawned instances will have these security groups | list(string) |
n/a | yes |
service_name | The name of the service | string |
n/a | yes |
use_mixed_instances_policy | Whether to use ASG mixed instances policy or the plain launch template | bool |
true |
no |
user_data | The spawned instances will have this user data. Use the rendered value of a terraform's template_cloudinit_config data |
string |
" " |
no |
volume_size | The size of the volume in gigabytes | string |
"8" |
no |
volume_type | The type of volume. Can be standard, gp2, or io1 | string |
"gp2" |
no |
Name | Description |
---|---|
asg_desired_capacity | The desired capacity of the auto scaling group; it may be useful when doing blue/green asg deployment (create a new asg while copying the old's capacity) |
asg_name | The name of the auto scaling group |
launch_template_name | The name of the launch template used by the auto scaling group |
resource_naming_launch_template | The name of the launch template generated by resource-naming module. |
This module accepting or open for any contributions from anyone, please see the CONTRIBUTING.md for more detail about how to contribute to this module.
This module is under Apache License 2.0 - see the LICENSE file for details.