This Terraform module creates CloudWatch Log Metric Filters and associated Alarms to monitor EC2 instance state changes, based on specified events. It ensures that critical instance state changes are tracked and alerts are sent to a specified SNS topic.
- Creates CloudWatch Log Metric Filters for specified EC2 instances.
- Sets up CloudWatch Alarms that trigger based on state changes detected in the filters.
- Flexible configuration for monitored events and alarm settings.
| Name | Version |
|---|---|
| terraform | ~> 1.0 |
| aws | ~> 5.46 |
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
| cw_log_group_name | The name of the CloudWatch log group storing CloudTrail logs. | string |
n/a | yes |
| cw_metric_filter_alarm_actions | The list of actions to execute when the alarm transitions into an ALARM state from any other state. | list(string) |
[] |
no |
| cw_metric_filter_alarm_comparison_operator | The comparison operator for the CloudWatch metric filter alarm. | string |
"GreaterThanOrEqualToThreshold" |
no |
| cw_metric_filter_alarm_evaluation_periods | The number of periods over which data is compared to the specified threshold. | number |
1 |
no |
| cw_metric_filter_alarm_period | The period in seconds over which the specified statistic is applied. | number |
300 |
no |
| cw_metric_filter_alarm_statistic | The statistic to apply to the alarm's associated metric. | string |
"Sum" |
no |
| cw_metric_filter_alarm_threshold | The value against which the specified statistic is compared. | number |
1 |
no |
| cw_metric_filter_namespace | The namespace for the CloudWatch metric filter. | string |
"EC2/Monitoring" |
no |
| cw_metric_filter_value | The value to publish to the CloudWatch metric. | string |
"1" |
no |
| ec2_instance_ids | List of EC2 instance IDs to monitor. | list(string) |
n/a | yes |
| ec2_instance_state_events | List of EC2 instance-related state events to monitor. | list(string) |
[ |
no |
module "terraform_trailwatch_ec2" {
source = "terraform-trailwatch-modules/ec2/aws"
ec2_instance_ids = ["i-12345678", "i-87654321"]
cw_log_group_name = "the-cloudtrail-log-group"
cw_metric_filter_alarm_actions = ["arn:aws:sns:region:account-id:sns-topic"]
}module "terraform_trailwatch_ec2" {
source = "terraform-trailwatch-modules/ec2/aws"
ec2_instance_ids = ["i-12345678", "i-87654321"]
ec2_instance_state_events = ["RunInstances", "StopInstances"]
cw_log_group_name = "the-cloudtrail-log-group"
cw_metric_filter_namespace = "EC2/Monitoring"
cw_metric_filter_value = "1"
cw_metric_filter_alarm_comparison_operator = "GreaterThanOrEqualToThreshold"
cw_metric_filter_alarm_evaluation_periods = 1
cw_metric_filter_alarm_period = 300
cw_metric_filter_alarm_statistic = "Sum"
cw_metric_filter_alarm_threshold = 1
cw_metric_filter_alarm_actions = ["arn:aws:sns:region:account-id:sns-topic"]
}For a detailed list of changes, please refer to the CHANGELOG.md.
This module is licensed under the MIT License.
