alicloud_ess_alarm

更新时间:

Provides a ESS alarm task resource.

For information about ess alarm, see CreateAlarm.

-> NOTE: Available since v1.15.0.

Example Usage


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"]
}

resource "alicloud_ess_scaling_rule" "default" {
  scaling_rule_name = local.name
  scaling_group_id  = alicloud_ess_scaling_group.default.id
  adjustment_type   = "TotalCapacity"
  adjustment_value  = 2
  cooldown          = 60
}

resource "alicloud_ess_alarm" "default" {
  name                = local.name
  description         = var.name
  alarm_actions       = [alicloud_ess_scaling_rule.default.ari]
  scaling_group_id    = alicloud_ess_scaling_group.default.id
  metric_type         = "system"
  metric_name         = "CpuUtilization"
  period              = 300
  statistics          = "Average"
  threshold           = 200.3
  comparison_operator = ">="
  evaluation_count    = 2
}

Module Support

You can use to the existing autoscaling-rule module to create alarm task, different type rules and scheduled task one-click.

Argument Reference

The following arguments are supported:

  • name - (Optional) The name for ess alarm.
  • description - (Optional) The description for the alarm.
  • effective - (Optional, Available since v1.231.0) The effective period of the event-triggered task. By default, the event-triggered task is in effect at all times.
  • enable - (Optional, Available in 1.48.0+) Whether to enable specific ess alarm. Default to true.
  • alarm_actions - (Required) The list of actions to execute when this alarm transition into an ALARM state. Each action is specified as ess scaling rule ari.
  • scaling_group_id - (Required, ForceNew) The scaling group associated with this alarm, the 'ForceNew' attribute is available in 1.56.0+.
  • metric_type - (Optional, ForceNew) The type for the alarm's associated metric. Supported value: system, custom. "system" means the metric data is collected by Aliyun Cloud Monitor Service(CMS), "custom" means the metric data is upload to CMS by users. Defaults to system.
  • metric_name - (Optional) The name for the alarm's associated metric. See dimensions below for details.
  • period - (Optional) The period in seconds over which the specified statistic is applied. Supported value: 60, 120, 300, 900. Defaults to 300.
  • statistics - (Optional) The statistic to apply to the alarm's associated metric. Supported value: Average, Minimum, Maximum. Defaults to Average.
  • threshold - (Optional) The value against which the specified statistics is compared.
  • comparison_operator - (Optional) The arithmetic operation to use when comparing the specified Statistic and Threshold. The specified Statistic value is used as the first operand. Supported value: >=, <=, >, <. Defaults to >=.
  • evaluation_count - (Optional) The number of times that needs to satisfies comparison condition before transition into ALARM state. Defaults to 3.
  • cloud_monitor_group_id - (Optional) Defines the application group id defined by CMS which is assigned when you upload custom metric to CMS, only available for custom metirc.
  • dimensions - (Optional) The dimension map for the alarm's associated metric. For all metrics, you can not set the dimension key as "scaling_group" or "userId", which is set by default, the second dimension for metric, such as "device" for "PackagesNetIn", need to be set by users. See dimensions below.
  • expressions - (Optional, Available since v1.225.1) Support multi alert rule. See expressions below for details.
  • expressions_logic_operator - (Optional, Available since v1.225.1) The relationship between the trigger conditions in the multi-metric alert rule.
  • state - (Optional) The status of the event-triggered task. Valid values:
  • ALARM: The alert condition is met and an alert is triggered.
  • OK: The alert condition is not met.
  • INSUFFICIENT_DATA: Auto Scaling cannot determine whether the alert condition is met due to insufficient data.

expressions

The Expressions mapping supports the following:

  • metric_name - (Optional) The name for the alarm's associated metric. See dimensions below for details.
  • period - (Optional) The period in seconds over which the specified statistic is applied. Supported value: 60, 120, 300, 900. Defaults to 300.
  • statistics - (Optional) The statistic to apply to the alarm's associated metric. Supported value: Average, Minimum, Maximum. Defaults to Average.
  • threshold - (Optional) The value against which the specified statistics is compared.
  • comparison_operator - (Optional) The arithmetic operation to use when comparing the specified Statistic and Threshold. The specified Statistic value is used as the first operand. Supported value: >=, <=, >, <. Defaults to >=.

dimensions

Supported metric names and dimensions :

MetricNameDimensions
CpuUtilizationuser_id,scaling_group
ClassicInternetRxuser_id,scaling_group
ClassicInternetTxuser_id,scaling_group
VpcInternetRxuser_id,scaling_group
VpcInternetTxuser_id,scaling_group
IntranetRxuser_id,scaling_group
IntranetTxuser_id,scaling_group
LoadAverageuser_id,scaling_group
MemoryUtilizationuser_id,scaling_group
SystemDiskReadBpsuser_id,scaling_group
SystemDiskWriteBpsuser_id,scaling_group
SystemDiskReadOpsuser_id,scaling_group
SystemDiskWriteOpsuser_id,scaling_group
PackagesNetInuser_id,scaling_group,device
PackagesNetOutuser_id,scaling_group,device
TcpConnectionuser_id,scaling_group,state

-> NOTE: Dimension user_id and scaling_group is automatically filled, which means you only need to care about dimension device and state when needed.

Attribute Reference

The following attributes are exported:

  • id - The id for ess alarm.

Import

Ess alarm can be imported using the id, e.g.

$ terraform import alicloud_ess_alarm.example asg-2ze500_045efffe-4d05