The AWS::CloudWatch::CompositeAlarm type specifies an alarm which aggregates the states of other Alarms (Metric or Composite Alarms) as defined by the AlarmRule expression
Creates a Composite alarm that comprises 2 sub-alarms. Note that the AWS provider resource for aws_cloudwatch_metric_alarm is used.
resource "awscc_cloudwatch_composite_alarm" "example" {
alarm_name = "example-composite-alarm"
alarm_description = "Example of a composite alarm with various actions"
alarm_rule = "ALARM(${aws_cloudwatch_metric_alarm.cpu_gte_80.alarm_name}) OR ALARM(${aws_cloudwatch_metric_alarm.status_gte_1.alarm_name})"
}
resource "aws_cloudwatch_metric_alarm" "cpu_gte_80" {
alarm_name = "cpu-gte-80"
alarm_description = "This metric monitors ec2 cpu utilization"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = 2
metric_name = "CPUUtilization"
namespace = "AWS/EC2"
period = 120
statistic = "Average"
threshold = 80
}
resource "aws_cloudwatch_metric_alarm" "status_gte_1" {
alarm_name = "status-gte-1"
alarm_description = "This metric monitors ec2 status check failed"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = 2
metric_name = "StatusCheckFailed"
namespace = "AWS/EC2"
period = 120
statistic = "Average"
threshold = 1
}
Creates a Composite alarm that comprises 2 sub-alarms. Note that AWS provider resources for aws_sns_topic and aws_cloudwatch_metric_alarm are used. It also uses different SNS topics for the various alarm actions.
resource "awscc_cloudwatch_composite_alarm" "example" {
alarm_name = "example-composite-alarm"
alarm_description = "Example of a composite alarm with various actions"
alarm_actions = [aws_sns_topic.example_alarm_actions.arn]
ok_actions = [aws_sns_topic.example_ok_actions.arn]
insufficient_data_actions = [aws_sns_topic.example_insufficient_data_actions.arn]
alarm_rule = "ALARM(${aws_cloudwatch_metric_alarm.cpu_gte_80.alarm_name}) OR ALARM(${aws_cloudwatch_metric_alarm.status_gte_1.alarm_name})"
}
resource "aws_sns_topic" "example_alarm_actions" {
name = "example-alarm-actions"
}
resource "aws_sns_topic" "example_ok_actions" {
name = "example-ok-actions"
}
resource "aws_sns_topic" "example_insufficient_data_actions" {
name = "example-insufficient-data-actions"
}
resource "aws_cloudwatch_metric_alarm" "cpu_gte_80" {
alarm_name = "cpu-gte-80"
alarm_description = "This metric monitors ec2 cpu utilization"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = 2
metric_name = "CPUUtilization"
namespace = "AWS/EC2"
period = 120
statistic = "Average"
threshold = 80
}
resource "aws_cloudwatch_metric_alarm" "status_gte_1" {
alarm_name = "status-gte-1"
alarm_description = "This metric monitors ec2 status check failed"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = 2
metric_name = "StatusCheckFailed"
namespace = "AWS/EC2"
period = 120
statistic = "Average"
threshold = 1
}
Creates a Composite alarm with an actions suppressor. Note that AWS provider resources for aws_sns_topic and aws_cloudwatch_metric_alarm are used.
resource "awscc_cloudwatch_composite_alarm" "example" {
alarm_name = "example-composite-alarm"
alarm_description = "Example of a composite alarm with actions suppressor"
actions_suppressor = aws_cloudwatch_metric_alarm.cpu_gte_80.alarm_name
actions_suppressor_extension_period = 60
actions_suppressor_wait_period = 60
alarm_actions = [aws_sns_topic.example_alarm_actions.arn]
alarm_rule = "ALARM(${aws_cloudwatch_metric_alarm.cpu_gte_80.alarm_name}) OR ALARM(${aws_cloudwatch_metric_alarm.status_gte_1.alarm_name})"
}
resource "aws_sns_topic" "example_alarm_actions" {
name = "example-alarm-actions"
}
resource "aws_cloudwatch_metric_alarm" "cpu_gte_80" {
alarm_name = "cpu-gte-80"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = 2
metric_name = "CPUUtilization"
namespace = "AWS/EC2"
period = 120
statistic = "Average"
threshold = 80
alarm_description = "This metric monitors ec2 cpu utilization"
insufficient_data_actions = []
}
resource "aws_cloudwatch_metric_alarm" "status_gte_1" {
alarm_name = "status-gte-1"
alarm_description = "This metric monitors ec2 status check failed"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = 2
metric_name = "StatusCheckFailed"
namespace = "AWS/EC2"
period = 120
statistic = "Average"
threshold = 1
}
alarm_rule
(String) Expression which aggregates the state of other Alarms (Metric or Composite Alarms)actions_enabled
(Boolean) Indicates whether actions should be executed during any changes to the alarm state. The default is TRUE.actions_suppressor
(String) Actions will be suppressed if the suppressor alarm is in the ALARM state. ActionsSuppressor can be an AlarmName or an Amazon Resource Name (ARN) from an existing alarm.actions_suppressor_extension_period
(Number) Actions will be suppressed if WaitPeriod is active. The length of time that actions are suppressed is in seconds.actions_suppressor_wait_period
(Number) Actions will be suppressed if ExtensionPeriod is active. The length of time that actions are suppressed is in seconds.alarm_actions
(List of String) The list of actions to execute when this alarm transitions into an ALARM state from any other state. Specify each action as an Amazon Resource Name (ARN).alarm_description
(String) The description of the alarmalarm_name
(String) The name of the Composite Alarminsufficient_data_actions
(List of String) The actions to execute when this alarm transitions to the INSUFFICIENT_DATA state from any other state. Each action is specified as an Amazon Resource Name (ARN).ok_actions
(List of String) The actions to execute when this alarm transitions to the OK state from any other state. Each action is specified as an Amazon Resource Name (ARN).tags
(Attributes List) A list of key-value pairs to associate with the composite alarm. You can associate as many as 50 tags with an alarm. (see below for nested schema)arn
(String) Amazon Resource Name (ARN) of the alarmid
(String) Uniquely identifies the resource.tags
Required:
key
(String) A unique identifier for the tag. The combination of tag keys and values can help you organize and categorize your resources.value
(String) The value for the specified tag key.Import is supported using the following syntax:
$ terraform import awscc_cloudwatch_composite_alarm.example <resource ID>