Skip to main content

Amazon EC2 Auto Scaling

Overview

The AWS Auto Scaling Module provides a reusable and scalable way to provision and manage Amazon EC2 Auto Scaling infrastructure using Terraform.
It abstracts the complexity of configuring Auto Scaling resources and enables developers to define infrastructure with minimal effort while following AWS best practices.

This module supports both resource creation and data sources for managing Auto Scaling Groups (ASG), Launch Configurations, and related policies.


Features

  • 🚀 Reusable & Modular – Predefined structure for resources and data modules.
  • 📈 Dynamic Scaling – Configure scaling policies based on CPU, memory, or custom CloudWatch metrics.
  • 🔄 Lifecycle Hooks – Supports lifecycle events for custom workflows during instance launch/termination.
  • 🧑‍🤝‍🧑 Multiple Attachments – Attach Auto Scaling groups to multiple target groups or load balancers.
  • 📜 Tagging & Notifications – Supports group tags and SNS notifications for scaling activities.
  • Scheduled Scaling – Define scheduled actions for predictable workload changes.
  • 🧩 Extensible – Easy to integrate with other Terraform modules (VPC, ELB, CloudWatch, etc.).

Core Concepts

  1. Resources Module

    • Creates and manages Auto Scaling components, including:
      • Auto Scaling Groups (ASG)
      • Launch Configurations
      • Scaling Policies
      • Lifecycle Hooks
      • Scheduled Actions
      • Notifications
  2. Data Module

    • Fetches information about existing Auto Scaling resources.
    • Useful for referencing attributes like group names, ARNs, and capacity.
  3. Separation of Concerns

    • resources/ handles ASG creation and configuration.
    • data/ is focused on reading and referencing existing ASG resources.
    • This separation ensures clarity, reusability, and modular design.

Sample Usage

# DEPLOY ANANTA CLOUD'S AUTO SCALING MODULE

module "autoscaling" {
source = "github.com/anantacloud/terraform-aws-autoscaling-module/modules/resources"

# ==========================
# REQUIRED VARIABLES
# ==========================
name_prefix = "my-asg"
launch_config_name = "my-launch-config"
min_size = 1
max_size = 3
desired_capacity = 2
vpc_zone_identifier = ["subnet-123456", "subnet-654321"]

# ==========================
# OPTIONAL VARIABLES
# ==========================
health_check_type = "EC2"
health_check_grace_period = 300

tags = {
Environment = "dev"
Project = "my-app"
}
}

Required

NameDescriptionTypeExample
name_prefixPrefix for the Auto Scaling Group namestring"my-asg"
launch_config_nameName of the Launch Configurationstring"my-launch-config"
min_sizeMinimum number of instances in the groupnumber1
max_sizeMaximum number of instances in the groupnumber3
desired_capacityDesired number of instancesnumber2
vpc_zone_identifierList of subnet IDs for the Auto Scaling Grouplist["subnet-123456"]

Optional

NameDescriptionTypeDefault
health_check_typeHealth check type for the group (EC2 or ELB)string"EC2"
health_check_grace_periodTime (in seconds) for grace period before checkingnumber300
tagsKey-value tags to apply to Auto Scaling resourcesmap{}