Skip to content

Latest commit

 

History

History
139 lines (117 loc) · 17.4 KB

README.md

File metadata and controls

139 lines (117 loc) · 17.4 KB

AWS EC2 Auto Scaling Terraform Module

This Terraform module deploys an AWS EC2 Auto Scaling Group.

Usage

Check valid versions on:

Install pre commit hooks.

Pleas run this command right after cloning the repository.

    pre-commit install

For that you may need to install the folowwing tools:

In order to run all checks at any point run the following command:

    pre-commit run --all-files

Requirements

Name Version
terraform >= 0.13
aws >= 4

Providers

Name Version
aws 4.0.0

Modules

No modules.

Resources

Name Type
aws_autoscaling_group.asg resource
aws_autoscaling_policy.cpu_high resource
aws_autoscaling_policy.cpu_low resource
aws_cloudwatch_metric_alarm.cpu_high_alarm resource
aws_cloudwatch_metric_alarm.cpu_low_alarm resource
aws_launch_configuration.lc resource

Inputs

Name Description Type Default Required
associate_public_ip_address (Optional) Associate a public ip address with an instance in a VPC. bool n/a yes
availability_zones (Required only for EC2-Classic) A list of one or more availability zones for the group. This parameter should not be specified when using vpc_zone_identifier. list(any) null no
default_cooldown (Optional, Default: 300) Time (in seconds) after a scaling activity completes before another scaling activity can start. number 300 no
desired_capacity (Optional) The number of Amazon EC2 instances that should be running in the group. (See also Waiting for Capacity.) number 1 no
ebs_block_device (Optional) Additional EBS block devices to attach to the instance. This is a list of maps, where each map should contain "device_name", "snapshot_id", "volume_type", "volume_size", "iops", "delete_on_termination" and "encrypted" list(any) [] no
ebs_optimized (Optional) If true, the launched EC2 instance will be EBS-optimized. bool false no
enable_monitoring (Optional) Enables/disables detailed monitoring. This is enabled by default. bool true no
enabled_metrics (Optional) A list of metrics to collect. The allowed values are GroupMinSize, GroupMaxSize, GroupDesiredCapacity, GroupInServiceInstances, GroupPendingInstances, GroupStandbyInstances, GroupTerminatingInstances, GroupTotalInstances. list(any)
[
"GroupMinSize",
"GroupMaxSize",
"GroupDesiredCapacity",
"GroupInServiceInstances",
"GroupPendingInstances",
"GroupStandbyInstances",
"GroupTerminatingInstances",
"GroupTotalInstances"
]
no
ephemeral_block_device (Optional) Customize Ephemeral (also known as "Instance Store") volumes on the instance. This is a list of maps, where each map should contain "device_name" and "virtual_name" list(any) [] no
force_delete (Optional) Allows deleting the autoscaling group without waiting for all instances in the pool to terminate. You can force an autoscaling group to delete even if it's in the process of scaling a resource. Normally, Terraform drains all the instances before deleting the group. This bypasses that behavior and potentially leaves resources dangling. bool false no
health_check_grace_period (Optional, Default: 300) Time (in seconds) after instance comes into service before checking health. number 300 no
health_check_type (Optional) "EC2" or "ELB". Controls how health checking is done. string "EC2" no
iam_instance_profile (Optional) The name attribute of the IAM instance profile to associate with launched instances. string "" no
image_id The EC2 image ID to launch. any n/a yes
instance_type The size of instance to launch. any n/a yes
key_name (Optional) The key name that should be used for the instance. string "" no
load_balancers (Optional) A list of elastic load balancer names to add to the autoscaling group names. Only valid for classic load balancers. For ALBs, use target_group_arns instead. list(any) [] no
max_size The maximum size of the auto scale group. number n/a yes
metrics_granularity (Optional) The granularity to associate with the metrics to collect. The only valid value is 1Minute. Default is 1Minute. string "1Minute" no
min_elb_capacity (Optional) Setting this causes Terraform to wait for this number of instances from this autoscaling group to show up healthy in the ELB only on creation. Updates will not wait on ELB instance number changes. (See also Waiting for Capacity.) number 0 no
min_size The minimum size of the auto scale group. (See also Waiting for Capacity.) number n/a yes
name_prefix Name prefix for resources on AWS any n/a yes
placement_group (Optional) The name of the placement group into which you'll launch your instances, if any. string "" no
placement_tenancy (Optional) The tenancy of the instance. Valid values are "default" or "dedicated", see AWS's Create Launch Configuration for more details string "default" no
protect_from_scale_in (Optional) Allows setting instance protection. The autoscaling group will not select instances with this setting for terminination during scale in events. bool false no
root_block_device (Optional) Customize details about the root block device of the instance. This is a list of maps, where each map should contain "volume_type", "volume_size", "iops" and "delete_on_termination" list(any) [] no
security_groups (Optional) A list of associated security group IDS. list(any) [] no
service_linked_role_arn (Optional) The ARN of the service-linked role that the ASG will use to call other AWS services string "" no
spot_price (Optional) The maximum price to use for reserving spot instances. (Default: On-demand price) string "" no
suspended_processes (Optional) A list of processes to suspend for the AutoScaling Group. The allowed values are Launch, Terminate, HealthCheck, ReplaceUnhealthy, AZRebalance, AlarmNotification, ScheduledActions, AddToLoadBalancer. Note that if you suspend either the Launch or Terminate process types, it can prevent your autoscaling group from functioning properly. list(any) [] no
target_group_arns (Optional) A list of aws_alb_target_group ARNs, for use with Application or Network Load Balancing. list(any) [] no
termination_policies (Optional) A list of policies to decide how the instances in the auto scale group should be terminated. The allowed values are OldestInstance, NewestInstance, OldestLaunchConfiguration, ClosestToNextInstanceHour, OldestLaunchTemplate, AllocationStrategy, Default. list(any)
[
"Default"
]
no
user_data (Optional) The user data to provide when launching the instance. Do not pass gzip-compressed data via this argument; see user_data_base64 instead. any null no
user_data_base64 (Optional) Can be used instead of user_data to pass base64-encoded binary data directly. Use this instead of user_data whenever the value is not a valid UTF-8 string. For example, gzip-encoded user data must be base64-encoded and passed via this argument to avoid corruption. any null no
vpc_classic_link_id (Optional) The ID of a ClassicLink-enabled VPC. Only applies to EC2-Classic instances. (eg. vpc-2730681a) string "" no
vpc_classic_link_security_groups (Optional) The IDs of one or more security groups for the specified ClassicLink-enabled VPC (eg. sg-46ae3d11). list [] no
vpc_zone_identifier (Optional) A list of subnet IDs to launch resources in. list(any) null no
wait_for_capacity_timeout (Optional) A maximum duration that Terraform should wait for ASG instances to be healthy before timing out (See also Waiting for Capacity.) Setting this to "0" causes Terraform to skip all Capacity Waiting behavior (Default: "10m"). string "10m" no
wait_for_elb_capacity (Optional) Setting this will cause Terraform to wait for exactly this number of healthy instances from this autoscaling group in all attached load balancers on both create and update operations. (Takes precedence over min_elb_capacity behavior.) (See also Waiting for Capacity.) number null no

Outputs

Name Description
asg_arn The ARN for this AutoScaling Group.
asg_availability_zones The availability zones of the autoscale group.
asg_default_cooldown Time between a scaling activity and the succeeding scaling activity.
asg_desired_capacity The number of Amazon EC2 instances that should be running in the group.
asg_health_check_grace_period Time after instance comes into service before checking health.
asg_health_check_type "EC2" or "ELB". Controls how health checking is done.
asg_id The autoscaling group id.
asg_launch_configuration The launch configuration of the autoscale group.
asg_load_balancers (Optional) The load balancer names associated with the autoscaling group.
asg_max_size The maximum size of the autoscale group.
asg_min_size The minimum size of the autoscale group.
asg_name The name of the autoscale group.
asg_target_group_arns (Optional) list of Target Group ARNs that apply to this AutoScaling Group.
asg_vpc_zone_identifier (Optional) The VPC zone identifier.
cpu_high_adjustment_type The scaling policy's adjustment type.
cpu_high_alarm_arn (Optional) list of Target Group ARNs that apply to this AutoScaling Group.
cpu_high_alarm_id The ID of the health check.
cpu_high_arn The ARN assigned by AWS to the scaling policy.
cpu_high_autoscaling_group_name The scaling policy's assigned autoscaling group.
cpu_high_name The scaling policy's name.
cpu_high_policy_type The scaling policy's type.
cpu_low_adjustment_type The scaling policy's adjustment type.
cpu_low_alarm_arn (Optional) list of Target Group ARNs that apply to this AutoScaling Group.
cpu_low_alarm_id The ID of the health check.
cpu_low_arn The ARN assigned by AWS to the scaling policy.
cpu_low_autoscaling_group_name The scaling policy's assigned autoscaling group.
cpu_low_name The scaling policy's name.
cpu_low_policy_type The scaling policy's type.
lc_id The ID of the launch configuration.
lc_name The name of the launch configuration.