AWS Autoscaling Group (ASG) Terraform Module
Terraform module to provision AutoScaling Group
on AWS.
Usage
Simple setup
Create a simple ASG with default configurations.
locals {
instance_userdata = <<USERDATA
#!/bin/sh
yum update -y
USERDATA
}
module "asg" {
source = "git@github.com:nclouds/terraform-aws-autoscaling.git?ref=v0.1.1"
iam_instance_profile = "arn:aws:iam::xxxxxxxx:instance-profile/xxxxxx"
user_data = base64encode(local.instance_userdata)
security_groups = ["sg-xxxxxxxxxxx"]
identifier = "example"
image_id = "ami-xxxxxxxx"
instance_type = "t3a.medium"
key_name = "nclouds-tf"
device_name = "/dev/xvda"
volume_size = 30
subnets = ["subnet-xxxxxxxxxxx", "subnet-xxxxxxxxxx"]
tags = {
Owner = "sysops"
env = "dev"
Cost_Center = "XYZ"
}
}
For more details on a working example, please visit examples/simple
Advanced Setup
If you want to create ASG with enhanced configuration e.g multiple instances etc., you can use the module like this:
locals {
instance_userdata = <<USERDATA
#!/bin/sh
yum update -y
USERDATA
}
module "asg" {
source = "git@github.com:nclouds/terraform-aws-autoscaling.git?ref=v0.1.1"
iam_instance_profile = "arn:aws:iam::xxxxxxxx:instance-profile/xxxxxx"
user_data_base64 = base64encode(local.instance_userdata)
associate_public_ip_address = true
security_groups = ["sg-xxxxxxxxxxx"]
identifier = "example"
image_id = "ami-xxxxxxxx"
instance_type = "t3a.medium"
key_name = "nclouds-tf"
device_name = "/dev/xvda"
volume_size = 30
volume_type = "gp2"
ebs_optimized = false
encrypted = true
instance_initiated_shutdown_behavior = "stop"
min_size = 2
max_size = 5
subnets = ["subnet-xxxxxxxxxxx", "subnet-xxxxxxxxxx"]
tags = {
Owner = "sysops"
env = "dev"
Cost_Center = "XYZ"
}
}
For more options refer to a working example at examples/advanced
Examples
Here are some working examples of using this module:
Requirements
Name | Version |
---|---|
terraform | >= 0.12 |
Providers
Name | Version |
---|---|
aws | n/a |
Modules
No modules.
Resources
Name | Type |
---|---|
aws_autoscaling_group.asg | resource |
aws_launch_template.launch_temlate | resource |
Inputs
Name | Description | Type | Default | Required |
---|---|---|---|---|
append_workspace | Appends the terraform workspace at the end of resource names, |
bool |
true |
no |
associate_public_ip_address | Associate a public ip address with an instance in a VPC | bool |
false |
no |
ebs_optimized | If true, the launched EC2 instance will be EBS-optimized | bool |
true |
no |
eks_cluster_id | If set add the tag kubernetes.io/cluster/ |
string |
"" |
no |
iam_instance_profile | The name attribute of the IAM instance profile to associate with launched instances | string |
n/a | yes |
identifier | The name for the resource | string |
n/a | yes |
image_id | AMI to use | string |
n/a | yes |
instance_type | EC2 Instance type to use | string |
"t2.micro" |
no |
key_name | The name of the key-pair to use | string |
n/a | yes |
max_size | Maximun number of instances in the ASG | number |
5 |
no |
min_size | Minimum number of instances in the ASG | number |
1 |
no |
protect_from_scale_in | Allows setting instance protection. The autoscaling group will not select instances with this setting for termination during scale in events. | bool |
false |
no |
security_groups | List of security groups to assign to instances | list(string) |
[] |
no |
subnets | A list of subnet IDs to launch resources in | list(string) |
n/a | yes |
tags | Tags to be applied to the resource | map(any) |
{} |
no |
user_data_base64 | base64-encoded user-data | string |
"" |
no |
volume_size | The size of the root ebs volume | number |
20 |
no |
volume_type | The type of volume. Can be ‘standard’, ‘gp2’, or ‘io1’ | string |
"gp2" |
no |
update_default_version | Update the Launch template version | bool |
true |
no |
device_name | The name of the device to mount | string |
"/dev/xvda" |
no |
iops | The amount of provisioned IOPS. This must be set with a volume_type of “io1/io2” | number |
"null" |
no |
monitoring | The launched EC2 instance will have detailed monitoring enabled, if its true | bool |
"false" |
no |
market_type | To allocate resource in spot / ondemand | string |
"null" |
no |
credit_specification | The credit specification of the instance standard / unlimited for T2/T3 | string |
"standard" |
no |
Outputs
Name | Description |
---|---|
output | n/a |
Contributing
If you want to contribute to this repository check all the guidelines specified here before submitting a new PR.