-
Notifications
You must be signed in to change notification settings - Fork 523
/
cloudwatch_metric_alarm.go
51 lines (43 loc) 路 1.14 KB
/
cloudwatch_metric_alarm.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package aws
import (
"github.com/infracost/infracost/internal/resources/aws"
"github.com/infracost/infracost/internal/schema"
)
func getCloudwatchMetricAlarmRegistryItem() *schema.RegistryItem {
return &schema.RegistryItem{
Name: "aws_cloudwatch_metric_alarm",
CoreRFunc: newCloudwatchMetricAlarm,
}
}
func newCloudwatchMetricAlarm(d *schema.ResourceData) schema.CoreResource {
region := d.Get("region").String()
comparisonOperator := d.Get("comparison_operator").String()
var metricCount int64
var period int64
if len(d.Get("metric_query").Array()) > 0 {
metricCount = 0
for _, metric := range d.Get("metric_query.#.metric").Array() {
metrics := metric.Array()
if len(metrics) == 0 {
continue
}
metricCount++
for _, m := range metrics {
if period == 0 && m.Get("period").Exists() {
period = m.Get("period").Int()
}
}
}
} else {
metricCount = 1
period = d.Get("period").Int()
}
r := &aws.CloudwatchMetricAlarm{
Address: d.Address,
Region: region,
ComparisonOperator: comparisonOperator,
Metrics: metricCount,
Period: period,
}
return r
}