github.com/wata727/tflint@v0.12.2-0.20191013070026-96dd0d36f385/rules/awsrules/models/aws_cloudwatch_metric_alarm_invalid_unit.go (about) 1 // This file generated by `tools/model-rule-gen/main.go`. DO NOT EDIT 2 3 package models 4 5 import ( 6 "log" 7 8 hcl "github.com/hashicorp/hcl/v2" 9 "github.com/wata727/tflint/tflint" 10 ) 11 12 // AwsCloudwatchMetricAlarmInvalidUnitRule checks the pattern is valid 13 type AwsCloudwatchMetricAlarmInvalidUnitRule struct { 14 resourceType string 15 attributeName string 16 enum []string 17 } 18 19 // NewAwsCloudwatchMetricAlarmInvalidUnitRule returns new rule with default attributes 20 func NewAwsCloudwatchMetricAlarmInvalidUnitRule() *AwsCloudwatchMetricAlarmInvalidUnitRule { 21 return &AwsCloudwatchMetricAlarmInvalidUnitRule{ 22 resourceType: "aws_cloudwatch_metric_alarm", 23 attributeName: "unit", 24 enum: []string{ 25 "Seconds", 26 "Microseconds", 27 "Milliseconds", 28 "Bytes", 29 "Kilobytes", 30 "Megabytes", 31 "Gigabytes", 32 "Terabytes", 33 "Bits", 34 "Kilobits", 35 "Megabits", 36 "Gigabits", 37 "Terabits", 38 "Percent", 39 "Count", 40 "Bytes/Second", 41 "Kilobytes/Second", 42 "Megabytes/Second", 43 "Gigabytes/Second", 44 "Terabytes/Second", 45 "Bits/Second", 46 "Kilobits/Second", 47 "Megabits/Second", 48 "Gigabits/Second", 49 "Terabits/Second", 50 "Count/Second", 51 "None", 52 }, 53 } 54 } 55 56 // Name returns the rule name 57 func (r *AwsCloudwatchMetricAlarmInvalidUnitRule) Name() string { 58 return "aws_cloudwatch_metric_alarm_invalid_unit" 59 } 60 61 // Enabled returns whether the rule is enabled by default 62 func (r *AwsCloudwatchMetricAlarmInvalidUnitRule) Enabled() bool { 63 return true 64 } 65 66 // Severity returns the rule severity 67 func (r *AwsCloudwatchMetricAlarmInvalidUnitRule) Severity() string { 68 return tflint.ERROR 69 } 70 71 // Link returns the rule reference link 72 func (r *AwsCloudwatchMetricAlarmInvalidUnitRule) Link() string { 73 return "" 74 } 75 76 // Check checks the pattern is valid 77 func (r *AwsCloudwatchMetricAlarmInvalidUnitRule) Check(runner *tflint.Runner) error { 78 log.Printf("[TRACE] Check `%s` rule for `%s` runner", r.Name(), runner.TFConfigPath()) 79 80 return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { 81 var val string 82 err := runner.EvaluateExpr(attribute.Expr, &val) 83 84 return runner.EnsureNoError(err, func() error { 85 found := false 86 for _, item := range r.enum { 87 if item == val { 88 found = true 89 } 90 } 91 if !found { 92 runner.EmitIssue( 93 r, 94 `unit is not a valid value`, 95 attribute.Expr.Range(), 96 ) 97 } 98 return nil 99 }) 100 }) 101 }