awscc_autoscaling_auto_scaling_group (Resource)

The AWS::AutoScaling::AutoScalingGroup resource defines an Amazon EC2 Auto Scaling group, which is a collection of Amazon EC2 instances that are treated as a logical grouping for the purposes of automatic scaling and management. For more information about Amazon EC2 Auto Scaling, see the Amazon EC2 Auto Scaling User Guide. Amazon EC2 Auto Scaling configures instances launched as part of an Auto Scaling group using either a launch template or a launch configuration. We strongly recommend that you do not use launch configurations. They do not provide full functionality for Amazon EC2 Auto Scaling or Amazon EC2. For more information, see Launch configurations and Migrate CloudFormation stacks from launch configurations to launch templates in the Amazon EC2 Auto Scaling User Guide.

Example Usage

Basic

An Auto Scaling group and a launch template.

resource "awscc_autoscaling_auto_scaling_group" "example" {
  max_size = "1"
  min_size = "0"

  launch_template = {
    version            = awscc_ec2_launch_template.example.latest_version_number
    launch_template_id = awscc_ec2_launch_template.example.id
  }

  desired_capacity    = "1"
  vpc_zone_identifier = [
    "subnetIdAz1",
    "subnetIdAz2",
    "subnetIdAz3"
  ]

  depends_on = [
    awscc_ec2_launch_template.example
  ]
}

resource "awscc_ec2_launch_template" "example" {
  launch_template_data = {
    image_id      = data.aws_ami.amazon_linux.id
    instance_type = "t2.micro"
  }
  launch_template_name = "${data.aws_caller_identity.current.account_id}-launch-template"
}

data "aws_caller_identity" "current" {}

data "aws_ami" "amazon_linux" {
  most_recent = true
  owners      = ["amazon"]
  filter {
    name   = "name"
    values = ["amzn2-ami-hvm-*-gp2"]
  }

  filter {
    name   = "root-device-type"
    values = ["ebs"]
  }

  filter {
    name   = "virtualization-type"
    values = ["hvm"]
  }

  filter {
    name   = "architecture"
    values = ["x86_64"]
  }
}

Metrics Collection

Auto Scaling group with CloudWatch monitoring enabled

resource "awscc_autoscaling_auto_scaling_group" "example" {
  max_size = "1"
  min_size = "0"

  launch_template = {
    version            = awscc_ec2_launch_template.example.latest_version_number
    launch_template_id = awscc_ec2_launch_template.example.id
  }

  desired_capacity    = "1"

  vpc_zone_identifier = [
    "subnetIdAz1",
    "subnetIdAz2",
    "subnetIdAz3"
  ]

  metrics_collection = [{
    granularity = "1Minute"
    metrics = [
      "GroupMinSize",
      "GroupMaxSize"
    ]
  }]
}

resource "awscc_ec2_launch_template" "example" {
  launch_template_data = {
    image_id      = data.aws_ami.amazon_linux.id
    instance_type = "t2.micro"
  }
  launch_template_name = "${data.aws_caller_identity.current.account_id}-launch-template"
}

data "aws_caller_identity" "current" {}

data "aws_ami" "amazon_linux" {
  most_recent = true
  owners      = ["amazon"]
  filter {
    name   = "name"
    values = ["amzn2-ami-hvm-*-gp2"]
  }

  filter {
    name   = "root-device-type"
    values = ["ebs"]
  }

  filter {
    name   = "virtualization-type"
    values = ["hvm"]
  }

  filter {
    name   = "architecture"
    values = ["x86_64"]
  }
}

Schema

Required

Optional

Read-Only

Nested Schema for instance_maintenance_policy

Optional:

Nested Schema for launch_template

Required:

Optional:

Nested Schema for lifecycle_hook_specification_list

Required:

Optional:

Nested Schema for metrics_collection

Required:

Optional:

Nested Schema for mixed_instances_policy

Required: md5-c84bd8525e3c1ab80111b74621999749 Optional: md5-49f0bd16b5195530a02528d60e3142db

Nested Schema for mixed_instances_policy.launch_template

Required: md5-6d6c5a1823fce8d058cb80010c44838e Optional: md5-8b55bbecb74a957ef70ad185fb4062c4

Nested Schema for mixed_instances_policy.launch_template.launch_template_specification

Required: md5-3e215b08e827fc4e7401ad8b68133197 Optional: md5-585f676574fdaa581c38627fced6bd1e

Nested Schema for mixed_instances_policy.launch_template.overrides

Optional: md5-62af44320c5548525ca4860184118767

Nested Schema for mixed_instances_policy.launch_template.overrides.instance_requirements

Required: md5-af92a73f22536f5a12c11ad3338ceb28 Optional: md5-61a79a972654816f9ed3a2e3356ea8a9

Default: Any manufacturer

  • accelerator_names (Set of String) Lists the accelerators that must be on an instance type.

    Default: Any accelerator

  • accelerator_total_memory_mi_b (Attributes) The minimum and maximum total memory size for the accelerators on an instance type, in MiB. Default: No minimum or maximum limits (see below for nested schema)
  • accelerator_types (Set of String) Lists the accelerator types that must be on an instance type.

    Default: Any accelerator type

  • allowed_instance_types (List of String) The instance types to apply your specified attributes against. All other instance types are ignored, even if they match your specified attributes. You can use strings with one or more wild cards, represented by an asterisk (*), to allow an instance type, size, or generation. The following are examples: m5.8xlarge, c5*.*, m5a.*, r*, *3*. For example, if you specify c5*, Amazon EC2 Auto Scaling will allow the entire C5 instance family, which includes all C5a and C5n instance types. If you specify m5a.*, Amazon EC2 Auto Scaling will allow all the M5a instance types, but not the M5n instance types. If you specify AllowedInstanceTypes, you can't specify ExcludedInstanceTypes. Default: All instance types
  • bare_metal (String) Indicates whether bare metal instance types are included, excluded, or required. Default: excluded
  • baseline_ebs_bandwidth_mbps (Attributes) The minimum and maximum baseline bandwidth performance for an instance type, in Mbps. For more information, see Amazon EBS–optimized instances in the Amazon EC2 User Guide for Linux Instances. Default: No minimum or maximum limits (see below for nested schema)
  • burstable_performance (String) Indicates whether burstable performance instance types are included, excluded, or required. For more information, see Burstable performance instances in the Amazon EC2 User Guide for Linux Instances. Default: excluded
  • cpu_manufacturers (Set of String) Lists which specific CPU manufacturers to include.

    Don't confuse the CPU hardware manufacturer with the CPU hardware architecture. Instances will be launched with a compatible CPU architecture based on the Amazon Machine Image (AMI) that you specify in your launch template. Default: Any manufacturer

  • excluded_instance_types (List of String) The instance types to exclude. You can use strings with one or more wild cards, represented by an asterisk (*), to exclude an instance family, type, size, or generation. The following are examples: m5.8xlarge, c5*.*, m5a.*, r*, *3*. For example, if you specify c5*, you are excluding the entire C5 instance family, which includes all C5a and C5n instance types. If you specify m5a.*, Amazon EC2 Auto Scaling will exclude all the M5a instance types, but not the M5n instance types. If you specify ExcludedInstanceTypes, you can't specify AllowedInstanceTypes. Default: No excluded instance types
  • instance_generations (Set of String) Indicates whether current or previous generation instance types are included.

    Default: Any current or previous generation

  • local_storage (String) Indicates whether instance types with instance store volumes are included, excluded, or required. For more information, see Amazon EC2 instance store in the Amazon EC2 User Guide for Linux Instances. Default: included
  • local_storage_types (Set of String) Indicates the type of local storage that is required.

    Default: Any local storage type

  • max_spot_price_as_percentage_of_optimal_on_demand_price (Number) [Price protection] The price protection threshold for Spot Instances, as a percentage of an identified On-Demand price. The identified On-Demand price is the price of the lowest priced current generation C, M, or R instance type with your specified attributes. If no current generation C, M, or R instance type matches your attributes, then the identified price is from either the lowest priced current generation instance types or, failing that, the lowest priced previous generation instance types that match your attributes. When Amazon EC2 Auto Scaling selects instance types with your attributes, we will exclude instance types whose price exceeds your specified threshold. The parameter accepts an integer, which Amazon EC2 Auto Scaling interprets as a percentage. To indicate no price protection threshold, specify a high value, such as 999999. If you set DesiredCapacityType to vcpu or memory-mib, the price protection threshold is based on the per-vCPU or per-memory price instead of the per instance price. Only one of SpotMaxPricePercentageOverLowestPrice or MaxSpotPriceAsPercentageOfOptimalOnDemandPrice can be specified. If you don't specify either, then SpotMaxPricePercentageOverLowestPrice is used and the value for that parameter defaults to 100.
  • memory_gi_b_per_v_cpu (Attributes) The minimum and maximum amount of memory per vCPU for an instance type, in GiB. Default: No minimum or maximum limits (see below for nested schema)
  • network_bandwidth_gbps (Attributes) The minimum and maximum amount of network bandwidth, in gigabits per second (Gbps). Default: No minimum or maximum limits (see below for nested schema)
  • network_interface_count (Attributes) The minimum and maximum number of network interfaces for an instance type. Default: No minimum or maximum limits (see below for nested schema)
  • on_demand_max_price_percentage_over_lowest_price (Number) [Price protection] The price protection threshold for On-Demand Instances, as a percentage higher than an identified On-Demand price. The identified On-Demand price is the price of the lowest priced current generation C, M, or R instance type with your specified attributes. If no current generation C, M, or R instance type matches your attributes, then the identified price is from either the lowest priced current generation instance types or, failing that, the lowest priced previous generation instance types that match your attributes. When Amazon EC2 Auto Scaling selects instance types with your attributes, we will exclude instance types whose price exceeds your specified threshold. The parameter accepts an integer, which Amazon EC2 Auto Scaling interprets as a percentage. To turn off price protection, specify a high value, such as 999999. If you set DesiredCapacityType to vcpu or memory-mib, the price protection threshold is applied based on the per-vCPU or per-memory price instead of the per instance price. Default: 20
  • require_hibernate_support (Boolean) Indicates whether instance types must provide On-Demand Instance hibernation support. Default: false
  • spot_max_price_percentage_over_lowest_price (Number) [Price protection] The price protection threshold for Spot Instances, as a percentage higher than an identified Spot price. The identified Spot price is the price of the lowest priced current generation C, M, or R instance type with your specified attributes. If no current generation C, M, or R instance type matches your attributes, then the identified price is from either the lowest priced current generation instance types or, failing that, the lowest priced previous generation instance types that match your attributes. When Amazon EC2 Auto Scaling selects instance types with your attributes, we will exclude instance types whose price exceeds your specified threshold. The parameter accepts an integer, which Amazon EC2 Auto Scaling interprets as a percentage. To turn off price protection, specify a high value, such as 999999. If you set DesiredCapacityType to vcpu or memory-mib, the price protection threshold is based on the per-vCPU or per-memory price instead of the per instance price. Only one of SpotMaxPricePercentageOverLowestPrice or MaxSpotPriceAsPercentageOfOptimalOnDemandPrice can be specified. Default: 100
  • total_local_storage_gb (Attributes) The minimum and maximum total local storage size for an instance type, in GB. Default: No minimum or maximum limits (see below for nested schema)
  • Nested Schema for mixed_instances_policy.launch_template.overrides.weighted_capacity.memory_mi_b

    Optional:

    Nested Schema for mixed_instances_policy.launch_template.overrides.weighted_capacity.v_cpu_count

    Optional:

    Nested Schema for mixed_instances_policy.launch_template.overrides.weighted_capacity.accelerator_count

    Optional:

    Nested Schema for mixed_instances_policy.launch_template.overrides.weighted_capacity.accelerator_total_memory_mi_b

    Optional:

    Nested Schema for mixed_instances_policy.launch_template.overrides.weighted_capacity.baseline_ebs_bandwidth_mbps

    Optional:

    Nested Schema for mixed_instances_policy.launch_template.overrides.weighted_capacity.memory_gi_b_per_v_cpu

    Optional:

    Nested Schema for mixed_instances_policy.launch_template.overrides.weighted_capacity.network_bandwidth_gbps

    Optional:

    Nested Schema for mixed_instances_policy.launch_template.overrides.weighted_capacity.network_interface_count

    Optional:

    Nested Schema for mixed_instances_policy.launch_template.overrides.weighted_capacity.total_local_storage_gb

    Optional:

    Nested Schema for mixed_instances_policy.launch_template.overrides.launch_template_specification

    Required:

    Optional:

    Nested Schema for mixed_instances_policy.instances_distribution

    Optional:

    Nested Schema for notification_configuration

    Required:

    Optional:

    Nested Schema for notification_configurations

    Required:

    Optional:

    Nested Schema for tags

    Required:

    Import

    Import is supported using the following syntax:

    $ terraform import awscc_autoscaling_auto_scaling_group.example <resource ID>