Skip to content

Commit 9010cc0

Browse files
feat(aws_instance): treat missing data on cloudwatchmetric (#184)
* feat(aws_instance): treat missing data on cloudwatchmetric * Add metric_treat_missing_data variable to examples/complete --------- Co-authored-by: Joe Niland <[email protected]>
1 parent bf54345 commit 9010cc0

File tree

7 files changed

+89
-63
lines changed

7 files changed

+89
-63
lines changed

README.md

Lines changed: 64 additions & 63 deletions
Large diffs are not rendered by default.

cloudwatch-alarm.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ resource "aws_cloudwatch_metric_alarm" "default" {
2020
statistic = var.statistic_level
2121
threshold = var.metric_threshold
2222
depends_on = [null_resource.check_alarm_action]
23+
treat_missing_data = var.metric_treat_missing_data
2324

2425
dimensions = {
2526
InstanceId = one(aws_instance.default[*].id)

docs/terraform.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
| <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 |
105105
| <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 |
106106
| <a name="input_metric_threshold"></a> [metric\_threshold](#input\_metric\_threshold) | The value against which the specified statistic is compared | `number` | `1` | no |
107+
| <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 |
107108
| <a name="input_monitoring"></a> [monitoring](#input\_monitoring) | Launched EC2 instance will have detailed monitoring enabled | `bool` | `true` | no |
108109
| <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 |
109110
| <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 |

examples/complete/fixtures.us-east-2.tfvars

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,5 @@ security_group_rules = [
5555
]
5656

5757
ssh_public_key_path = "/secrets"
58+
59+
metric_treat_missing_data = "notBreaching"

examples/complete/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ module "ec2_instance" {
8585
security_group_rules = var.security_group_rules
8686
instance_profile = aws_iam_instance_profile.test.name
8787
tenancy = var.tenancy
88+
metric_treat_missing_data = var.metric_treat_missing_data
8889

8990
depends_on = [aws_iam_instance_profile.test]
9091

examples/complete/variables.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,13 @@ variable "tenancy" {
4646
error_message = "Tenancy field can only be one of default, dedicated, host"
4747
}
4848
}
49+
50+
variable "metric_treat_missing_data" {
51+
type = string
52+
description = "Sets how this alarm is to handle missing data points. The following values are supported: `missing`, `ignore`, `breaching` and `notBreaching`. Defaults to `missing`."
53+
default = "missing"
54+
validation {
55+
condition = contains(["missing", "ignore", "breaching", "notBreaching"], var.metric_treat_missing_data)
56+
error_message = "The value of metric_treat_missing_data must be one of the following: \"missing\", \"ignore\", \"breaching\", and \"notBreaching\"."
57+
}
58+
}

variables.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,16 @@ variable "metric_threshold" {
279279
default = 1
280280
}
281281

282+
variable "metric_treat_missing_data" {
283+
type = string
284+
description = "Sets how this alarm is to handle missing data points. The following values are supported: `missing`, `ignore`, `breaching` and `notBreaching`. Defaults to `missing`."
285+
default = "missing"
286+
validation {
287+
condition = contains(["missing", "ignore", "breaching", "notBreaching"], var.metric_treat_missing_data)
288+
error_message = "The value of metric_treat_missing_data must be one of the following: \"missing\", \"ignore\", \"breaching\", and \"notBreaching\"."
289+
}
290+
}
291+
282292
variable "disable_alarm_action" {
283293
type = bool
284294
default = false

0 commit comments

Comments
 (0)