Resource: aws_autoscalingplans_scaling_plan

Manages an AWS Auto Scaling scaling plan. More information can be found in the AWS Auto Scaling User Guide.

Example Usage

Basic Dynamic Scaling

data "aws_availability_zones" "available" {}

resource "aws_autoscaling_group" "example" {
  name_prefix = "example"

  launch_configuration = aws_launch_configuration.example.name
  availability_zones   = [data.aws_availability_zones.available.names[0]]

  min_size = 0
  max_size = 3

  tags = [
    {
      key                 = "application"
      value               = "example"
      propagate_at_launch = true
    },
  ]
}

resource "aws_autoscalingplans_scaling_plan" "example" {
  name = "example-dynamic-cost-optimization"

  application_source {
    tag_filter {
      key    = "application"
      values = ["example"]
    }
  }

  scaling_instruction {
    max_capacity       = 3
    min_capacity       = 0
    resource_id        = format("autoScalingGroup/%s", aws_autoscaling_group.example.name)
    scalable_dimension = "autoscaling:autoScalingGroup:DesiredCapacity"
    service_namespace  = "autoscaling"

    target_tracking_configuration {
      predefined_scaling_metric_specification {
        predefined_scaling_metric_type = "ASGAverageCPUUtilization"
      }

      target_value = 70
    }
  }
}

Basic Predictive Scaling

data "aws_availability_zones" "available" {}

resource "aws_autoscaling_group" "example" {
  name_prefix = "example"

  launch_configuration = aws_launch_configuration.example.name
  availability_zones   = [data.aws_availability_zones.available.names[0]]

  min_size = 0
  max_size = 3

  tags = [
    {
      key                 = "application"
      value               = "example"
      propagate_at_launch = true
    },
  ]
}

resource "aws_autoscalingplans_scaling_plan" "example" {
  name = "example-predictive-cost-optimization"

  application_source {
    tag_filter {
      key    = "application"
      values = ["example"]
    }
  }

  scaling_instruction {
    disable_dynamic_scaling = true

    max_capacity       = 3
    min_capacity       = 0
    resource_id        = format("autoScalingGroup/%s", aws_autoscaling_group.example.name)
    scalable_dimension = "autoscaling:autoScalingGroup:DesiredCapacity"
    service_namespace  = "autoscaling"

    target_tracking_configuration {
      predefined_scaling_metric_specification {
        predefined_scaling_metric_type = "ASGAverageCPUUtilization"
      }

      target_value = 70
    }

    predictive_scaling_max_capacity_behavior = "SetForecastCapacityToMaxCapacity"
    predictive_scaling_mode                  = "ForecastAndScale"

    predefined_load_metric_specification {
      predefined_load_metric_type = "ASGTotalCPUUtilization"
    }
  }
}

Argument Reference

This resource supports the following arguments:

The application_source object supports the following:

The tag_filter object supports the following:

The scaling_instruction object supports the following:

The customized_load_metric_specification object supports the following:

The predefined_load_metric_specification object supports the following:

The target_tracking_configuration object supports the following:

The customized_scaling_metric_specification object supports the following:

The predefined_scaling_metric_specification object supports the following:

Attribute Reference

This resource exports the following attributes in addition to the arguments above:

Import

In Terraform v1.5.0 and later, use an import block to import Auto Scaling scaling plans using the name. For example:

import {
  to = aws_autoscalingplans_scaling_plan.example
  id = "MyScale1"
}

Using terraform import, import Auto Scaling scaling plans using the name. For example:

% terraform import aws_autoscalingplans_scaling_plan.example MyScale1