Terraform Module for AWS Autoscaling Group
Note: You must specify either launch_configuration, launch_template, or mixed_instances_policy.
This is a stable example. It should successfully build out of the box
This examples does is built on Construct Libraries marked "Stable" and does not have any infrastructure prerequisites to build.
This module Provides a AutoScalling Group resources in AWS cloud provider.....
This module needs Terraform 0.12.19 or newer. You can download the latest Terraform version from here.
This module deploys aws services details are in respective feature branches.
Below we are able to check the resources that are being created as part of this module call:
- EC2 AutoScalling Group
To use this module, add the following call to your code:
Example with launch_tamplate
module "autoscaling_group" {
source = "git::https://github.com/nitinda/terraform-module-aws-autoscaling-group.git?ref=master"
providers = {
aws = aws.services
}
name_prefix = "ec2-asg-"
desired_capacity = 1
max_size = 1
min_size = 0
default_cooldown = 1
vpc_zone_identifier = var.vpc_zone_identifier
health_check_grace_period = 1
launch_template = {
id = var.launch_template_id
version = "$Latest"
}
tags = {
Project = "POC"
Environment = "prod"
}
}
Example with mixed_instances_policy
module "autoscaling_group" {
source = "git::https://github.com/nitinda/terraform-module-aws-autoscaling-group.git?ref=master"
providers = {
aws = aws.services
}
name_prefix = "ec2-asg-"
desired_capacity = 0
max_size = 0
min_size = 0
default_cooldown = 1
vpc_zone_identifier = var.vpc_zone_identifier
health_check_grace_period = 1
launch_template = {}
mixed_instances_policy = {
launch_template = {
launch_template_specification = {
launch_template_id = var.launch_template_id
version = "$Latest"
}
override = [
{
instance_type = "m4.large"
},
{
instance_type = "t3.large"
}
]
}
instances_distribution = {
spot_allocation_strategy = "capacity-optimized"
on_demand_base_capacity = 0
on_demand_percentage_above_base_capacity = 0
}
}
tags = {
Project = "POC"
Environment = "prod"
}
}
module "autoscaling_group" {
source = "git::https://github.com/nitinda/terraform-module-aws-autoscaling-group.git?ref=master"
providers = {
aws = aws.services
}
name_prefix = "rabbitmq-asg-ec2-"
desired_capacity = 0
max_size = 0
min_size = 0
default_cooldown = 1
vpc_zone_identifier = [ module.vpc_subnet_public_1a.id, module.vpc_subnet_public_1b.id]
health_check_grace_period = 1
mixed_instances_policy = {
launch_template = {
launch_template_specification = {
launch_template_id = module.launch_template.id
version = "$Latest"
}
override = [
{
instance_type = "t3.xlarge"
},
{
instance_type = "t3.large"
}
]
}
instances_distribution = {
spot_allocation_strategy = "capacity-optimized"
on_demand_base_capacity = 0
on_demand_percentage_above_base_capacity = 0
}
}
tag = merge(
var.common_tags,
{
Environment = "prod"
Name = "ec2-insance"
}
)
tags = merge(
var.common_tags,
{
Environment = "prod"
Name = "asg-ec2"
}
)
}
The variables required in order for the module to be successfully called from the deployment repository are the following:
Variable | Description | Type | Argument Status | Default Value |
---|---|---|---|---|
name | The name of the auto scaling group | string | Optional | null |
name_prefix | Creates a unique name beginning with the specified prefix | string | Optional | null |
max_size | The maximum size of the auto scale group | number | Optional | 0 |
min_size | The minimum size of the auto scale group | number | Optional | 0 |
default_cooldown | The amount of time, in seconds, after a scaling activity completes before another scaling activity can start |
string | Optional | 60 |
launch_configuration | The name of the launch configuration to use | string | Optional | null |
launch_template | Nested argument with Launch template specification to use to launch instances |
any | Optional | {} |
mixed_instances_policy | Configuration block containing settings to define launch targets for Auto Scaling groups |
any | Optional | {} |
initial_lifecycle_hook | One or more Lifecycle Hooks to attach to the autoscaling group before instances are launched |
any | Optional | {} |
health_check_grace_period | Time (in seconds) after instance comes | number | Optional | 300 |
health_check_type | Type of health check | string | Optional | EC2 |
desired_capacity | The number of Amazon EC2 instances | number | Optional | 0 |
force_delete | Allows deleting the autoscaling group without waiting for all instances in the pool to terminate |
bool | Optional | true |
load_balancers | A list of elastic load balancer names to add to the autoscaling group names |
list(string) | Optional | [] |
vpc_zone_identifier | A list of subnet IDs to launch resources | list(string) | Optional | [] |
target_group_arns | A list of aws_alb_target_group ARNs, for use with Application or Network Load Balancing |
list(string) | Optional | [] |
termination_policies | A list of policies to decide how the instances in the auto scale group should be terminated |
list(string) | Optional | [] |
suspended_processes | A list of processes to suspend for the AutoScaling Group | list(string) | Optional | [] |
tag | A list of tag blocks | any | Optional | [] |
placement_group | The name of the placement group into which you'll launch your instances, if any |
string | Optional | null |
metrics_granularity | The granularity to associate with the metrics to collect |
string | Optional | 1Minute |
enabled_metrics | A list of metrics to collect | list(string) | Optional | [] |
max_instance_lifetime | The maximum amount of time, in seconds, that an instance can be in service |
string | Optional | null |
This module has the following outputs:
- id
- name
- arn
In order for the variables to be accessed on module level please use the syntax below:
module.<module_name>.<output_variable_name>
The output variable is able to be accessed through terraform state file using the syntax below:
data.terraform_remote_state.<module_name>.<output_variable_name>
Module maintained by Module maintained by the - Nitin Das