Provides a ESS scaling group resource which is a collection of ECS instances with the same application scenarios.
It defines the maximum and minimum numbers of ECS instances in the group, and their associated Server Load Balancer instances, RDS instances, and other attributes.
For information about ess scaling rule, see CreateScalingGroup.
variable "name" {
default = "terraform-example"
}
resource "random_integer" "default" {
min = 10000
max = 99999
}
locals {
name = "${var.name}-${random_integer.default.result}"
}
data "alicloud_zones" "default" {
available_disk_category = "cloud_efficiency"
available_resource_creation = "VSwitch"
}
data "alicloud_instance_types" "default" {
availability_zone = data.alicloud_zones.default.zones[0].id
cpu_core_count = 2
memory_size = 4
}
data "alicloud_images" "default" {
name_regex = "^ubuntu_18.*64"
most_recent = true
owners = "system"
}
resource "alicloud_vpc" "default" {
vpc_name = local.name
cidr_block = "172.16.0.0/16"
}
resource "alicloud_vswitch" "default" {
vpc_id = alicloud_vpc.default.id
cidr_block = "172.16.0.0/24"
zone_id = data.alicloud_zones.default.zones[0].id
vswitch_name = local.name
}
resource "alicloud_security_group" "default" {
name = local.name
vpc_id = alicloud_vpc.default.id
}
resource "alicloud_security_group_rule" "default" {
type = "ingress"
ip_protocol = "tcp"
nic_type = "intranet"
policy = "accept"
port_range = "22/22"
priority = 1
security_group_id = alicloud_security_group.default.id
cidr_ip = "172.16.0.0/24"
}
resource "alicloud_vswitch" "default2" {
vpc_id = alicloud_vpc.default.id
cidr_block = "172.16.1.0/24"
zone_id = data.alicloud_zones.default.zones[0].id
vswitch_name = "${var.name}-bar"
}
resource "alicloud_ess_scaling_group" "default" {
min_size = 1
max_size = 1
scaling_group_name = local.name
default_cooldown = 20
vswitch_ids = [alicloud_vswitch.default.id, alicloud_vswitch.default2.id]
removal_policies = ["OldestInstance", "NewestInstance"]
}
You can use to the existing autoscaling module to create a scaling group, configuration and lifecycle hook one-click.
The following arguments are supported:
min_size
- (Required) Minimum number of ECS instances in the scaling group. Value range: [0, 2000].
NOTE: From version 1.204.1, min_size
can be set to 2000
.max_size
- (Required) Maximum number of ECS instances in the scaling group. Value range: [0, 2000].
NOTE: From version 1.204.1, max_size
can be set to 2000
.desired_capacity
- (Optional, Available since v1.76.0) Expected number of ECS instances in the scaling group. Value range: [min_size, max_size].scaling_group_name
- (Optional) Name shown for the scaling group, which must contain 2-64 characters (English or Chinese), starting with numbers, English letters or Chinese characters, and can contain numbers, underscores _
, hyphens -
, and decimal points .
. If this parameter is not specified, the default value is ScalingGroupId.default_cooldown
- (Optional) Default cool-down time (in seconds) of the scaling group. Value range: [0, 86400]. The default value is 300s.vswitch_id
- (Deprecated) It has been deprecated from version 1.7.1 and new field 'vswitch_ids' replaces it.vswitch_ids
- (Optional) List of virtual switch IDs in which the ecs instances to be launched.removal_policies
- (Optional) RemovalPolicy is used to select the ECS instances you want to remove from the scaling group when multiple candidates for removal exist. Optional values:
db_instance_ids
- (Optional) If an RDS instance is specified in the scaling group, the scaling group automatically attaches the Intranet IP addresses of its ECS instances to the RDS access whitelist.
loadbalancer_ids
- (Optional) If a Server Load Balancer instance is specified in the scaling group, the scaling group automatically attaches its ECS instances to the Server Load Balancer instance.
depends_on
argument
targeting your alicloud_slb_listener
in order to make sure the listener with its HealthCheck configuration is ready before creating your scaling group).multi_az_policy
- (Optional, ForceNew) Multi-AZ scaling group ECS instance expansion and contraction strategy. PRIORITY, BALANCE or COST_OPTIMIZED(Available since v1.54.0).on_demand_base_capacity
- (Optional, Available since v1.54.0) The minimum amount of the Auto Scaling group's capacity that must be fulfilled by On-Demand Instances. This base portion is provisioned first as your group scales.on_demand_percentage_above_base_capacity
- (Optional, Available since v1.54.0) Controls the percentages of On-Demand Instances and Spot Instances for your additional capacity beyond OnDemandBaseCapacity. spot_instance_pools
- (Optional, Available since v1.54.0) The number of Spot pools to use to allocate your Spot capacity. The Spot pools is composed of instance types of lowest price.spot_instance_remedy
- (Optional, Available since v1.54.0) Whether to replace spot instances with newly created spot/onDemand instance when receive a spot recycling message.group_deletion_protection
- (Optional, Available since v1.102.0) Specifies whether the scaling group deletion protection is enabled. true
or false
, Default value: false
. launch_template_id
- (Optional, Available since v1.141.0) Instance launch template ID, scaling group obtains launch configuration from instance launch template, see Launch Template. Creating scaling group from launch template enable group automatically.launch_template_version
- (Optional, Available since v1.159.0) The version number of the launch template. Valid values are the version number, Latest
, or Default
, Default value: Default
.group_type
- (Optional, ForceNew, Available since v1.164.0) Resource type within scaling group. Optional values: ECS, ECI. Default to ECS.health_check_type
- (Optional, Available since v1.193.0) Resource type within scaling group. Optional values: ECS, NONE. Default to ECS.tags
- (Optional, Available since v1.160.0) A mapping of tags to assign to the resource.
protected_instances
- (Optional, Available since v1.182.0) Set or unset instances within group into protected status.launch_template_override
- (Optional, Available since v1.216.0) The details of the instance types that are specified by using the Extend Instance Type of Launch Template feature.. See launch_template_override
below for details.launch_template_override
The launchTemplateOverride mapping supports the following:
weighted_capacity
- (Optional) The weight of the instance type in launchTemplateOverride.instance_type
- (Optional) The instance type in launchTemplateOverride.spot_price_limit
- (Optional) The maximum bid price of instance type in launchTemplateOverride.The following attributes are exported:
id
- The scaling group ID.ESS scaling group can be imported using the id, e.g.
$ terraform import alicloud_ess_scaling_group.example asg-abc123456