Skip to content

Commit

Permalink
update with new variables
Browse files Browse the repository at this point in the history
  • Loading branch information
anmolnagpal committed Sep 2, 2020
1 parent 978c158 commit bc0dda6
Show file tree
Hide file tree
Showing 17 changed files with 641 additions and 13 deletions.
87 changes: 84 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ This module has a few dependencies:
**IMPORTANT:** Since the `master` branch used in `source` varies based on new modifications, we suggest that you use the release versions [here](https://github.com/clouddrove/terraform-aws-cloudwatch-alarms/releases).


### Simple Example
Here is an example of how you can use this module in your inventory structure:
Here are some examples of how you can use this module in your inventory structure:
### Basic Example
```hcl
module "alarm" {
source = "https://github.com/clouddrove/terraform-aws-cloudwatch-alarms.git?ref=tags/0.12.3"
source = "https://github.com/clouddrove/terraform-aws-cloudwatch-alarms.git?ref=tags/0.12.4"
name = "alarm"
application = "clouddrove"
environment = "test"
Expand All @@ -96,6 +96,83 @@ Here is an example of how you can use this module in your inventory structure:
}
```

### Anomaly Example
```hcl
module "alarm" {
source = "https://github.com/clouddrove/terraform-aws-cloudwatch-alarms.git?ref=tags/0.12.4"
name = "alarm"
application = "clouddrove"
environment = "test"
label_order = ["environment", "name", "application"]
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 = []
}
```

### Epression Example
```hcl
module "alarm" {
source = "https://github.com/clouddrove/terraform-aws-cloudwatch-alarms.git?ref=tags/0.12.4"
name = "alarm"
application = "clouddrove"
environment = "test"
label_order = ["environment", "name", "application"]
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 = []
}
```




Expand All @@ -115,6 +192,7 @@ Here is an example of how you can use this module in your inventory structure:
| 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 | `<list>` | no |
| label\_order | Label order, e.g. `name`,`application`. | list | `<list>` | no |
Expand All @@ -124,8 +202,11 @@ Here is an example of how you can use this module in your inventory structure:
| 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 | `<list>` | no |
| period | The period in seconds over which the specified statistic is applied. | number | `"120"` | no |
| query\_expressions | values for metric query expression. | map | `<map>` | no |
| query\_metrics | values for metric query metrics. | map | `<map>` | 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 |

## Outputs

Expand Down
83 changes: 80 additions & 3 deletions README.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ include:

# How to use this project
usage : |-
### Simple Example
Here is an example of how you can use this module in your inventory structure:
Here are some examples of how you can use this module in your inventory structure:
### Basic Example
```hcl
module "alarm" {
source = "https://github.com/clouddrove/terraform-aws-cloudwatch-alarms.git?ref=tags/0.12.3"
source = "https://github.com/clouddrove/terraform-aws-cloudwatch-alarms.git?ref=tags/0.12.4"
name = "alarm"
application = "clouddrove"
environment = "test"
Expand All @@ -58,4 +58,81 @@ usage : |-
instance_id = "i-xxxxxxxxxxxxx"
}
}
```
### Anomaly Example
```hcl
module "alarm" {
source = "https://github.com/clouddrove/terraform-aws-cloudwatch-alarms.git?ref=tags/0.12.4"
name = "alarm"
application = "clouddrove"
environment = "test"
label_order = ["environment", "name", "application"]
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 = []
}
```
### Epression Example
```hcl
module "alarm" {
source = "https://github.com/clouddrove/terraform-aws-cloudwatch-alarms.git?ref=tags/0.12.4"
name = "alarm"
application = "clouddrove"
environment = "test"
label_order = ["environment", "name", "application"]
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 = []
}
```
File renamed without changes.
121 changes: 121 additions & 0 deletions _example/anomaly_example/example.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
provider "aws" {
region = "eu-west-1"
}

module "vpc" {
source = "git::https://github.com/clouddrove/terraform-aws-vpc.git"

name = "vpc"
application = "clouddrove"
environment = "test"
label_order = ["environment", "name", "application"]

cidr_block = "172.16.0.0/16"
}

module "public_subnets" {
source = "git::https://github.com/clouddrove/terraform-aws-subnet.git"

name = "public-subnet"
application = "clouddrove"
environment = "test"
label_order = ["environment", "name", "application"]

availability_zones = ["eu-west-1b", "eu-west-1c"]
vpc_id = module.vpc.vpc_id
cidr_block = module.vpc.vpc_cidr_block
ipv6_cidr_block = module.vpc.ipv6_cidr_block
type = "public"
igw_id = module.vpc.igw_id
}

module "http-https" {
source = "git::https://github.com/clouddrove/terraform-aws-security-group.git"

name = "http-https"
application = "clouddrove"
label_order = ["environment", "name", "application"]

environment = "test"
vpc_id = module.vpc.vpc_id
allowed_ip = ["0.0.0.0/0"]
allowed_ports = [80, 443]
}

module "ssh" {
source = "git::https://github.com/clouddrove/terraform-aws-security-group.git"

name = "ssh"
application = "clouddrove"
label_order = ["environment", "name", "application"]

environment = "test"
vpc_id = module.vpc.vpc_id
allowed_ip = [module.vpc.vpc_cidr_block]
allowed_ports = [22]
}

module "ec2" {
source = "git::https://github.com/clouddrove/terraform-aws-ec2.git"

name = "ec2-instance"
application = "clouddrove"
environment = "test"
label_order = ["environment", "name", "application"]

instance_count = 1
ami = "ami-08d658f84a6d84a80"
ebs_optimized = "false"
instance_type = "t2.nano"
monitoring = false
associate_public_ip_address = true
tenancy = "default"
disk_size = 8
vpc_security_group_ids_list = [module.ssh.security_group_ids, module.http-https.security_group_ids]
subnet_ids = tolist(module.public_subnets.public_subnet_id)

assign_eip_address = "true"

ebs_volume_enabled = "true"
ebs_volume_type = "gp2"
ebs_volume_size = 30
user_data = "./_bin/user_data.sh"
}

module "alarm" {
source = "../../"

name = "alarm"
application = "clouddrove"
environment = "test"
label_order = ["environment", "name", "application"]

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 = []
}
File renamed without changes.
2 changes: 2 additions & 0 deletions _example/basic_example/_bin/user_data.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
sudo apt-get update && sudo apt-get install -y python
7 changes: 4 additions & 3 deletions _example/example.tf → _example/basic_example/example.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module "public_subnets" {
availability_zones = ["eu-west-1b", "eu-west-1c"]
vpc_id = module.vpc.vpc_id
cidr_block = module.vpc.vpc_cidr_block
ipv6_cidr_block = module.vpc.ipv6_cidr_block
type = "public"
igw_id = module.vpc.igw_id
}
Expand Down Expand Up @@ -82,23 +83,23 @@ module "ec2" {
}

module "alarm" {
source = "../"
source = "../../"

name = "alarm"
application = "clouddrove"
environment = "test"
label_order = ["environment", "name", "application"]

alarm_name = "cpu-alarm"
comparison_operator = "LessThanThreshold"
comparison_operator = "GreaterThanOrEqualToThreshold"
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:xxxxxxxxxxxx:test"]
alarm_actions = []

actions_enabled = true
insufficient_data_actions = []
Expand Down
9 changes: 9 additions & 0 deletions _example/basic_example/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
output "arn" {
value = module.alarm.*.arn
description = "The ARN of the cloudwatch metric alarm."
}

output "tags" {
value = module.alarm.tags
description = "A mapping of tags to assign to the Cloudwatch Alarm."
}
2 changes: 2 additions & 0 deletions _example/expression_example/_bin/user_data.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
sudo apt-get update && sudo apt-get install -y python
Loading

0 comments on commit bc0dda6

Please sign in to comment.