Terraform module creates Cloudwatch Alarm on AWS for monitoriing AWS services.
We eat, drink, sleep and most importantly love DevOps. We are working towards strategies for standardizing architecture while ensuring security for the infrastructure. We are strong believer of the philosophy Bigger problems are always solved by breaking them into smaller manageable problems. Resonating with microservices architecture, it is considered best-practice to run database, cluster, storage in smaller connected yet manageable pieces within the infrastructure.
This module is basically combination of Terraform open source and includes automatation tests and examples. It also helps to create and improve your infrastructure with minimalistic code instead of maintaining the whole infrastructure code yourself.
We have fifty plus terraform modules. A few of them are comepleted and are available for open source usage while a few others are in progress.
This module has a few dependencies:
- Terraform 0.13
- Go
- github.com/stretchr/testify/assert
- github.com/gruntwork-io/terratest/modules/terraform
IMPORTANT: Since the master
branch used in source
varies based on new modifications, we suggest that you use the release versions here.
Here are some examples of how you can use this module in your inventory structure:
module "alarm" {
source = "clouddrove/cloudwatch-alarms/aws"
version = "0.15.0"
name = "alarm"
environment = "test"
label_order = ["name", "environment"]
alarm_name = "cpu-alarm"
comparison_operator = "LessThanThreshold"
evaluation_periods = 2
metric_name = "CPUUtilization"
namespace = "AWS/EC2"
period = "60"
statistic = "Average"
threshold = "40"
alarm_description = "This metric monitors ec2 cpu utilization"
alarm_actions = ["arn:aws:sns:eu-west-1:xxxxxxxxxxx:test"]
actions_enabled = true
insufficient_data_actions = []
ok_actions = []
dimensions = {
instance_id = "i-xxxxxxxxxxxxx"
}
}
module "alarm" {
source = "clouddrove/cloudwatch-alarms/aws"
version = "0.15.0"
name = "alarm"
environment = "test"
label_order = ["name", "environment"]
alarm_name = "cpu-alarm"
comparison_operator = "GreaterThanUpperThreshold"
evaluation_periods = 2
threshold_metric_id = "e1"
query_expressions = [{
id = "e1"
expression = "ANOMALY_DETECTION_BAND(m1)"
label = "CPUUtilization (Expected)"
return_data = "true"
}]
query_metrics = [{
id = "m1"
return_data = "true"
metric_name = "CPUUtilization"
namespace = "AWS/EC2"
period = "120"
stat = "Average"
unit = "Count"
dimensions = {
InstanceId = module.ec2.instance_id[0]
}
}]
alarm_description = "This metric monitors ec2 cpu utilization"
alarm_actions = []
actions_enabled = true
insufficient_data_actions = []
ok_actions = []
}
module "alarm" {
source = "clouddrove/cloudwatch-alarms/aws"
version = "0.15.0"
name = "alarm"
environment = "test"
label_order = ["name", "environment"]
expression_enabled = true
alarm_name = "cpu-alarm"
comparison_operator = "GreaterThanUpperThreshold"
evaluation_periods = 2
threshold = 40
query_expressions = [{
id = "e1"
expression = "ANOMALY_DETECTION_BAND(m1)"
label = "CPUUtilization (Expected)"
return_data = "true"
}]
query_metrics = [{
id = "m1"
return_data = "true"
metric_name = "CPUUtilization"
namespace = "AWS/EC2"
period = "120"
stat = "Average"
unit = "Count"
dimensions = {
InstanceId = module.ec2.instance_id[0]
}
}]
alarm_description = "This metric monitors ec2 cpu utilization"
alarm_actions = []
actions_enabled = true
insufficient_data_actions = []
ok_actions = []
}
Name | Description | Type | Default | Required |
---|---|---|---|---|
actions_enabled | Indicates whether or not actions should be executed during any changes to the alarm's state. | bool |
true |
no |
alarm_actions | The list of actions to execute when this alarm transitions into an ALARM state from any other state. | list(any) |
[] |
no |
alarm_description | The description for the alarm. | string |
"" |
no |
alarm_name | The descriptive name for the alarm. | string |
n/a | yes |
comparison_operator | The arithmetic operation to use when comparing the specified Statistic and Threshold. | string |
n/a | yes |
dimensions | Dimensions for metrics. | map |
{} |
no |
enabled | Enable alarm. | bool |
true |
no |
environment | Environment (e.g. prod , dev , staging ). |
string |
"" |
no |
evaluation_periods | The number of periods over which data is compared to the specified threshold. | number |
n/a | yes |
expression_enabled | Enable alarm with expression. | bool |
false |
no |
instance_id | The instance ID. | string |
"" |
no |
insufficient_data_actions | The list of actions to execute when this alarm transitions into an INSUFFICIENT_DATA state from any other state. | list(any) |
[] |
no |
label_order | Label order, e.g. name ,application . |
list(any) |
[] |
no |
managedby | ManagedBy, eg 'CloudDrove'. | string |
"[email protected]" |
no |
metric_name | The name for the alarm's associated metric. | string |
"CPUUtilization" |
no |
name | Name (e.g. app or cluster ). |
string |
"" |
no |
namespace | The namespace for the alarm's associated metric. | string |
"AWS/EC2" |
no |
ok_actions | The list of actions to execute when this alarm transitions into an OK state from any other state. | list(any) |
[] |
no |
period | The period in seconds over which the specified statistic is applied. | number |
120 |
no |
query_expressions | values for metric query expression. | list |
[ |
no |
query_metrics | values for metric query metrics. | list |
[ |
no |
repository | Terraform current module repo | string |
"https://github.com/clouddrove/terraform-aws-cloudwatch-alarms" |
no |
statistic | The statistic to apply to the alarm's associated metric. | string |
"Average" |
no |
threshold | The value against which the specified statistic is compared. | number |
40 |
no |
threshold_metric_id | If this is an alarm based on an anomaly detection model, make this value match the ID of the ANOMALY_DETECTION_BAND function. | string |
"" |
no |
Name | Description |
---|---|
arn | The ARN of the cloudwatch metric alarm. |
id | The ID of the health check. |
tags | A mapping of tags to assign to the resource. |
In this module testing is performed with terratest and it creates a small piece of infrastructure, matches the output like ARN, ID and Tags name etc and destroy infrastructure in your AWS account. This testing is written in GO, so you need a GO environment in your system.
You need to run the following command in the testing folder:
go test -run Test
If you come accross a bug or have any feedback, please log it in our issue tracker, or feel free to drop us an email at [email protected].
If you have found it worth your time, go ahead and give us a ★ on our GitHub!
At CloudDrove, we offer expert guidance, implementation support and services to help organisations accelerate their journey to the cloud. Our services include docker and container orchestration, cloud migration and adoption, infrastructure automation, application modernisation and remediation, and performance engineering.
We are The Cloud Experts!
We ❤️ Open Source and you can check out our other modules to get help with your new Cloud ideas.