This template sets up a predictive scaling plan for an AWS Auto Scaling group, using forecast data to scale and optimize for CPU utilization while disabling dynamic scaling.

Terraform Template

data "aws_availability_zones" "available" {
}

resource "aws_autoscaling_group" "example" {
  availability_zones = [data.aws_availability_zones.available.names[0]]
  launch_configuration = "aws_launch_configuration.example.name"
  max_size = 3
  min_size = 0
  name_prefix = "example"
  name = ""
}

resource "aws_autoscalingplans_scaling_plan" "example" {

  application_source {

    tag_filter {
      key = "application"
      values = ["example"]
    }
  }
  name = "example-predictive-cost-optimization"

  scaling_instruction {
    disable_dynamic_scaling = true
    max_capacity = 3
    min_capacity = 0

    predefined_load_metric_specification {
      predefined_load_metric_type = "ASGTotalCPUUtilization"
    }
    predictive_scaling_max_capacity_behavior = "SetForecastCapacityToMaxCapacity"
    predictive_scaling_mode = "ForecastAndScale"
    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
    }
  }
}