Skip to content

Commit

Permalink
feat(aws_instance): treat missing data on cloudwatchmetric (#184)
Browse files Browse the repository at this point in the history
* feat(aws_instance): treat missing data on cloudwatchmetric

* Add metric_treat_missing_data variable to examples/complete

---------

Co-authored-by: Joe Niland <joe@originalmind.com.au>
  • Loading branch information
haidargit and joe-niland committed Feb 9, 2024
1 parent bf54345 commit 9010cc0
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 63 deletions.
127 changes: 64 additions & 63 deletions README.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions cloudwatch-alarm.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ resource "aws_cloudwatch_metric_alarm" "default" {
statistic = var.statistic_level
threshold = var.metric_threshold
depends_on = [null_resource.check_alarm_action]
treat_missing_data = var.metric_treat_missing_data

dimensions = {
InstanceId = one(aws_instance.default[*].id)
Expand Down
1 change: 1 addition & 0 deletions docs/terraform.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
| <a name="input_metric_name"></a> [metric\_name](#input\_metric\_name) | The name for the alarm's associated metric. Allowed values can be found in https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/ec2-metricscollected.html | `string` | `"StatusCheckFailed_Instance"` | no |
| <a name="input_metric_namespace"></a> [metric\_namespace](#input\_metric\_namespace) | The namespace for the alarm's associated metric. Allowed values can be found in https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/aws-namespaces.html | `string` | `"AWS/EC2"` | no |
| <a name="input_metric_threshold"></a> [metric\_threshold](#input\_metric\_threshold) | The value against which the specified statistic is compared | `number` | `1` | no |
| <a name="input_metric_treat_missing_data"></a> [metric\_treat\_missing\_data](#input\_metric\_treat\_missing\_data) | Sets how this alarm is to handle missing data points. The following values are supported: `missing`, `ignore`, `breaching` and `notBreaching`. Defaults to `missing`. | `string` | `"missing"` | no |
| <a name="input_monitoring"></a> [monitoring](#input\_monitoring) | Launched EC2 instance will have detailed monitoring enabled | `bool` | `true` | no |
| <a name="input_name"></a> [name](#input\_name) | ID element. Usually the component or solution name, e.g. 'app' or 'jenkins'.<br>This is the only ID element not also included as a `tag`.<br>The "name" tag is set to the full `id` string. There is no tag with the value of the `name` input. | `string` | `null` | no |
| <a name="input_namespace"></a> [namespace](#input\_namespace) | ID element. Usually an abbreviation of your organization name, e.g. 'eg' or 'cp', to help ensure generated IDs are globally unique | `string` | `null` | no |
Expand Down
2 changes: 2 additions & 0 deletions examples/complete/fixtures.us-east-2.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,5 @@ security_group_rules = [
]

ssh_public_key_path = "/secrets"

metric_treat_missing_data = "notBreaching"
1 change: 1 addition & 0 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ module "ec2_instance" {
security_group_rules = var.security_group_rules
instance_profile = aws_iam_instance_profile.test.name
tenancy = var.tenancy
metric_treat_missing_data = var.metric_treat_missing_data

depends_on = [aws_iam_instance_profile.test]

Expand Down
10 changes: 10 additions & 0 deletions examples/complete/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,13 @@ variable "tenancy" {
error_message = "Tenancy field can only be one of default, dedicated, host"
}
}

variable "metric_treat_missing_data" {
type = string
description = "Sets how this alarm is to handle missing data points. The following values are supported: `missing`, `ignore`, `breaching` and `notBreaching`. Defaults to `missing`."
default = "missing"
validation {
condition = contains(["missing", "ignore", "breaching", "notBreaching"], var.metric_treat_missing_data)
error_message = "The value of metric_treat_missing_data must be one of the following: \"missing\", \"ignore\", \"breaching\", and \"notBreaching\"."
}
}
10 changes: 10 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,16 @@ variable "metric_threshold" {
default = 1
}

variable "metric_treat_missing_data" {
type = string
description = "Sets how this alarm is to handle missing data points. The following values are supported: `missing`, `ignore`, `breaching` and `notBreaching`. Defaults to `missing`."
default = "missing"
validation {
condition = contains(["missing", "ignore", "breaching", "notBreaching"], var.metric_treat_missing_data)
error_message = "The value of metric_treat_missing_data must be one of the following: \"missing\", \"ignore\", \"breaching\", and \"notBreaching\"."
}
}

variable "disable_alarm_action" {
type = bool
default = false
Expand Down

0 comments on commit 9010cc0

Please sign in to comment.