Provides a ESS schedule resource.
For information about ess schedule task, see Scheduled Tasks.
variable "name" {
default = "terraform-example"
}
resource "random_integer" "default" {
min = 10000
max = 99999
}
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 = var.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 = var.name
}
resource "alicloud_security_group" "default" {
name = var.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_ess_scaling_group" "default" {
min_size = 1
max_size = 1
scaling_group_name = "${var.name}-${random_integer.default.result}"
vswitch_ids = [alicloud_vswitch.default.id]
removal_policies = ["OldestInstance", "NewestInstance"]
}
resource "alicloud_ess_scaling_configuration" "default" {
scaling_group_id = alicloud_ess_scaling_group.default.id
image_id = data.alicloud_images.default.images[0].id
instance_type = data.alicloud_instance_types.default.instance_types[0].id
security_group_id = alicloud_security_group.default.id
force_delete = "true"
}
resource "alicloud_ess_scaling_rule" "default" {
scaling_group_id = alicloud_ess_scaling_group.default.id
adjustment_type = "TotalCapacity"
adjustment_value = 2
cooldown = 60
}
resource "alicloud_ess_scheduled_task" "default" {
scheduled_action = alicloud_ess_scaling_rule.default.ari
launch_time = formatdate("YYYY-MM-DD'T'hh:mm'Z'", timeadd(timestamp(), "24h"))
scheduled_task_name = "${var.name}-${random_integer.default.result}"
}
You can use to the existing autoscaling-rule module to create scheduled task, different type rules and alarm task one-click.
The following arguments are supported:
scheduled_action
- (Optional) The operation to be performed when a scheduled task is triggered. Enter the unique identifier of a scaling rule. NOTE: You cannot specify scheduled_action
and scaling_group_id
at the same time.scheduled_task_name
- (Optional) Display name of the scheduled task, which must be 2-40 characters (English or Chinese) long.scaling_group_id
- (Optional, Available in 1.90.0+) The ID of the scaling group where the number of instances is modified when the scheduled task is triggered. After the ScalingGroupId
parameter is specified, the scaling method of the scheduled task is to specify the number of instances in a scaling group. You must specify at least one of the following parameters: MinValue
, MaxValue
, and DesiredCapacity
. NOTE: You cannot specify scheduled_action
and scaling_group_id
at the same time.min_value
- (Optional, Available in 1.90.0+) The minimum number of instances in a scaling group when the scaling method of the scheduled task is to specify the number of instances in a scaling group.max_value
- (Optional, Available in 1.90.0+) The maximum number of instances in a scaling group when the scaling method of the scheduled task is to specify the number of instances in a scaling group.desired_capacity
- (Optional, Available in 1.90.0+) The expected number of instances in a scaling group when the scaling method of the scheduled task is to specify the number of instances in a scaling group. NOTE: You must specify the DesiredCapacity
parameter when you create the scaling group.description
- (Optional) Description of the scheduled task, which is 2-200 characters (English or Chinese) long.launch_time
- (Optional) The time at which the scheduled task is triggered. Specify the time in the ISO 8601 standard in the YYYY-MM-DDThh:mmZ format.
The time must be in UTC. You cannot enter a time point later than 90 days from the date of scheduled task creation.
If the recurrence_type
parameter is specified, the task is executed repeatedly at the time specified by LaunchTime.
Otherwise, the task is only executed once at the date and time specified by LaunchTime.launch_expiration_time
- (Optional) The time period during which a failed scheduled task is retried. Unit: seconds. Valid values: 0 to 21600. Default value: 600recurrence_type
- (Optional) Specifies the recurrence type of the scheduled task. NOTE: You must specify RecurrenceType
, RecurrenceValue
, and RecurrenceEndTime
at the same time. Valid values:
recurrence_value
- (Optional) Specifies how often a scheduled task recurs. NOTE: You must specify RecurrenceType
, RecurrenceValue
, and RecurrenceEndTime
at the same time. The valid value depends on recurrence_type
recurrence_end_time
- (Optional) Specifies the end time after which the scheduled task is no longer repeated. Specify the time in the ISO 8601 standard in the YYYY-MM-DDThh:mm:ssZ format.
The time must be in UTC. You cannot enter a time point later than 365 days from the date of scheduled task creation. NOTE: You must specify RecurrenceType
, RecurrenceValue
, and RecurrenceEndTime
at the same time. task_enabled
- (Optional) Specifies whether to start the scheduled task. Default to true.The following attributes are exported:
id
- The schedule task ID.ESS schedule task can be imported using the id, e.g.
$ terraform import alicloud_ess_scheduled_task.example abc123456