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