From 07d0337dc82c5844ff6e9cac77ede0262a8bf67c Mon Sep 17 00:00:00 2001 From: Shirox Date: Fri, 28 Jun 2019 18:41:23 +0900 Subject: [PATCH 1/3] Add to support CloudWatch Alarm treat missing data. --- lib/terraforming/template/tf/cloud_watch_alarm.erb | 5 +++-- spec/lib/terraforming/resource/cloud_watch_alarm_spec.rb | 8 +++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/terraforming/template/tf/cloud_watch_alarm.erb b/lib/terraforming/template/tf/cloud_watch_alarm.erb index 4a859934..1b979552 100644 --- a/lib/terraforming/template/tf/cloud_watch_alarm.erb +++ b/lib/terraforming/template/tf/cloud_watch_alarm.erb @@ -1,5 +1,5 @@ <% alarms.each do |alarm| -%> -resource "aws_cloudwatch_metric_alarm" "<%= normalize_module_name(alarm.alarm_name) %>" { + resource "aws_cloudwatch_metric_alarm" "<%= normalize_module_name(alarm.alarm_name) %>" { alarm_name = "<%= alarm.alarm_name %>" comparison_operator = "<%= alarm.comparison_operator %>" evaluation_periods = "<%= alarm.evaluation_periods %>" @@ -8,6 +8,7 @@ resource "aws_cloudwatch_metric_alarm" "<%= normalize_module_name(alarm.alarm_na period = "<%= alarm.period %>" statistic = "<%= alarm.statistic %>" threshold = "<%= alarm.threshold %>" + treat_missing_data = "<%= alarm.treat_missing_data %>" alarm_description = "<%= alarm.alarm_description %>" <%- unless alarm.ok_actions.empty? -%> ok_actions = <%= alarm.ok_actions %> @@ -19,7 +20,7 @@ resource "aws_cloudwatch_metric_alarm" "<%= normalize_module_name(alarm.alarm_na actions_enabled = <%= alarm.actions_enabled %> <%- end -%> <%- unless alarm.dimensions.empty? -%> - dimensions { + dimensions = { <% alarm.dimensions.each do |dimension| -%> <%= dimension.name %> = "<%= dimension.value %>" <% end -%> diff --git a/spec/lib/terraforming/resource/cloud_watch_alarm_spec.rb b/spec/lib/terraforming/resource/cloud_watch_alarm_spec.rb index b2eb6dd1..fb71ac0a 100644 --- a/spec/lib/terraforming/resource/cloud_watch_alarm_spec.rb +++ b/spec/lib/terraforming/resource/cloud_watch_alarm_spec.rb @@ -22,6 +22,7 @@ module Resource ok_actions: [], period: 300, statistic: "Average", + treat_missing_data: "missing", threshold: 10000.0 }, { @@ -37,6 +38,7 @@ module Resource ok_actions: [], period: 120, statistic: "Average", + treat_missing_data: "notBreaching", threshold: 80.0 } ] @@ -58,9 +60,10 @@ module Resource period = "300" statistic = "Average" threshold = "10000.0" + treat_missing_data = "missing" alarm_description = "" alarm_actions = ["arn:aws:sns:region:account:lambda-alerts"] - dimensions { + dimensions = { FunctionName = "beep-beep" } } @@ -74,6 +77,7 @@ module Resource period = "120" statistic = "Average" threshold = "80.0" + treat_missing_data = "notBreaching" alarm_description = "This metric monitors ec2 cpu utilization" actions_enabled = false } @@ -102,6 +106,7 @@ module Resource "period" => "300", "statistic" => "Average", "threshold" => "10000.0", + "treat_missing_data" => "missing", "unit" => "", "insufficient_data_actions.#" => "0", "alarm_actions.#" => "1", @@ -128,6 +133,7 @@ module Resource "period" => "120", "statistic" => "Average", "threshold" => "80.0", + "treat_missing_data" => "notBreaching", "unit" => "", "insufficient_data_actions.#" => "0", "alarm_actions.#" => "0", From 614e027e003b540749041089f01eef8a12dbb5ef Mon Sep 17 00:00:00 2001 From: Shirox Date: Fri, 28 Jun 2019 18:45:33 +0900 Subject: [PATCH 2/3] Remove typo spaces. --- lib/terraforming/template/tf/cloud_watch_alarm.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/terraforming/template/tf/cloud_watch_alarm.erb b/lib/terraforming/template/tf/cloud_watch_alarm.erb index 1b979552..9ea08a66 100644 --- a/lib/terraforming/template/tf/cloud_watch_alarm.erb +++ b/lib/terraforming/template/tf/cloud_watch_alarm.erb @@ -1,5 +1,5 @@ <% alarms.each do |alarm| -%> - resource "aws_cloudwatch_metric_alarm" "<%= normalize_module_name(alarm.alarm_name) %>" { +resource "aws_cloudwatch_metric_alarm" "<%= normalize_module_name(alarm.alarm_name) %>" { alarm_name = "<%= alarm.alarm_name %>" comparison_operator = "<%= alarm.comparison_operator %>" evaluation_periods = "<%= alarm.evaluation_periods %>" From 388515025857e398aedf0f575010995dd74e068c Mon Sep 17 00:00:00 2001 From: Shirox Date: Thu, 4 Jul 2019 14:51:51 +0900 Subject: [PATCH 3/3] Fix a missing attribute in cwa. --- lib/terraforming/resource/cloud_watch_alarm.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/terraforming/resource/cloud_watch_alarm.rb b/lib/terraforming/resource/cloud_watch_alarm.rb index ec2d293a..b3a92af1 100644 --- a/lib/terraforming/resource/cloud_watch_alarm.rb +++ b/lib/terraforming/resource/cloud_watch_alarm.rb @@ -47,6 +47,7 @@ def alarm_attributes(alarm) "period" => alarm.period.to_s, "statistic" => alarm.statistic, "threshold" => alarm.threshold.to_s, + "treat_missing_data" => alarm.treat_missing_data, "unit" => sanitize(alarm.unit) } add_checksummed_attributes(attributes, alarm)