Skip to content

nitinda/terraform-module-aws-autoscaling-policy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Terraform Module: terraform-module-aws-autoscaling-policy

Terraform Module for AWS AutoScaling Scaling Policy


Code : Stable

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.


General

This module may be used to create AWS AutoScaling Scaling Policy resources in AWS cloud provider......


Prerequisites

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.


Features

Below we are able to check the resources that are being created as part of this module call:

  • AWS AutoScaling Scaling Policy

Usage

Using this repo

To use this module, add the following call to your code:

NOTE: You may want to omit desired_capacity attribute from attached aws_autoscaling_group when using autoscaling policies. It's good practice to pick either manual or dynamic (policy-based) scaling.

  • Example Usage Simple Scaling
module "autoscaling_policy_up" {
  source = "git::https://github.com/nitinda/terraform-module-aws-autoscaling-policy.git?ref=master"

  providers = {
    aws = aws.services
  }

  name                      = "scal_up"
  scaling_adjustment        = 1
  adjustment_type           = "ChangeInCapacity"
  cooldown                  = 10
  estimated_instance_warmup = 2
  autoscaling_group_name    = module.autoscaling_group.name  
}
  • Example Usage Target Scaling
module "autoscaling_policy_up" {
  source = "git::https://github.com/nitinda/terraform-module-aws-autoscaling-policy.git?ref=master"

  providers = {
    aws = aws.services
  }

  name                      = "scal_up"
  adjustment_type           = "ChangeInCapacity"
  estimated_instance_warmup = 2
  autoscaling_group_name    = module.autoscaling_group.name

  target_tracking_configuration = {
    predefined_metric_specification = {
      predefined_metric_type = "ASGAverageCPUUtilization"
    }
    target_value = 40.0
  }
}
  • Example Usage Step Scaling
module "autoscaling_policy_up" {
  source = "git::https://github.com/nitinda/terraform-module-aws-autoscaling-policy.git?ref=master"

  providers = {
    aws = aws.services
  }

  name                      = "scal_up"
  adjustment_type           = "ChangeInCapacity"
  estimated_instance_warmup = 2
  autoscaling_group_name    = module.autoscaling_group.name

  step_adjustment = [
    {
      metric_interval_lower_bound = 0
      metric_interval_upper_bound = 50
      scaling_adjustment          = 1
    }.
    {
      metric_interval_lower_bound = 50
      scaling_adjustment          = 2
    }
  ]
}

module "autoscaling_policy_down" {
  source = "git::https://github.com/nitinda/terraform-module-aws-autoscaling-policy.git?ref=master"

  providers = {
    aws = aws.services
  }

  name                      = "scal_up"
  adjustment_type           = "ChangeInCapacity"
  estimated_instance_warmup = 2
  autoscaling_group_name    = module.autoscaling_group.name

  step_adjustment = [
    {
      metric_interval_upper_bound = 0
      scaling_adjustment          = -1
    }
  ]
}

Inputs

The variables required in order for the module to be successfully called from the deployment repository are the following:

NOTE: You cannot create a metric alarm consisting of both statistic and extended_statistic parameters. You must choose one or the other

Variable Description Type Argument Status Default Value
name The name of the policy string Required
autoscaling_group_name The name of the autoscaling group string Required
adjustment_type Specifies whether the adjustment is an absolute number or a percentage of the current capacity. Valid values are ChangeInCapacity, ExactCapacity, and PercentChangeInCapacity string Optional null
policy_type The policy type, either "SimpleScaling", "StepScaling" or "TargetTrackingScaling". If this value isn't provided, AWS will default to "SimpleScaling" string Optional SimpleScaling
estimated_instance_warmup The estimated time, in seconds, until a newly launched instance will contribute CloudWatch metrics. Without a value, AWS will default to the group's specified cooldown period. number Optional null

The following arguments are only available to "SimpleScaling" type policies:

Variable Description Type Argument Status Default Value
cooldown The amount of time, in seconds, after a scaling activity completes and before the next scaling activity can start number Optional 0
scaling_adjustment The number of instances by which to scale. adjustment_type determines the interpretation of this number (e.g., as an absolute number or as a percentage of the existing Auto Scaling group size). A positive increment adds to the current capacity and a negative value removes from the current capacity. string Optional null

The following arguments are only available to "StepScaling" type policies:

Variable Description Type Argument Status Default Value
scaling_adjustment The aggregation type for the policy's metrics. Valid values are "Minimum", "Maximum", and "Average". Without a value, AWS will treat the aggregation type as "Average". string Optional Average
step_adjustment A set of adjustments that manage group scaling. any Optional []
step_adjustment {
    metric_interval_lower_bound = 0
    metric_interval_upper_bound = 50
    scaling_adjustment = 1
}

step_adjustment {
    metric_interval_lower_bound = 50
    scaling_adjustment = 2
}

The following fields are available in step adjustments:

Variable Description Type Argument Status Default Value
scaling_adjustment The number of members by which to scale, when the adjustment bounds are breached. A positive value scales up. A negative value scales down. string Required
metric_interval_lower_bound The lower bound for the difference between the alarm threshold and the CloudWatch metric. Without a value, AWS will treat this bound as infinity. string Optional null
metric_interval_upper_bound The upper bound for the difference between the alarm threshold and the CloudWatch metric. Without a value, AWS will treat this bound as infinity. The upper bound must be greater than the lower bound. string Optional null

The following arguments are only available to "TargetTrackingScaling" type policies:

Variable Description Type Argument Status Default Value
target_tracking_configuration A target tracking policy. These have the following structure. any Optional {}
target_tracking_configuration {
  predefined_metric_specification {
    predefined_metric_type = "ASGAverageCPUUtilization"
  }

  target_value = 40.0
}

target_tracking_configuration {
  customized_metric_specification {
    metric_dimension {
      name  = "fuga"
      value = "fuga"
    }

    metric_name = "hoge"
    namespace   = "hoge"
    statistic   = "Average"
  }

  target_value = 40.0
}

Outputs

General

This module has the following outputs:

The ARN assigned by AWS to the scaling policy : arn

The scaling policy's name : name

The scaling policy's adjustment type : adjustment_type

The scaling policy's type : policy_type


Usage

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>

Authors

Module maintained by Module maintained by the - Nitin Das

About

Provides an AutoScaling Scaling Policy resource.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages