github.com/wata727/tflint@v0.12.2-0.20191013070026-96dd0d36f385/rules/awsrules/models/aws_cloudwatch_metric_alarm_invalid_statistic.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 // AwsCloudwatchMetricAlarmInvalidStatisticRule checks the pattern is valid 13 type AwsCloudwatchMetricAlarmInvalidStatisticRule struct { 14 resourceType string 15 attributeName string 16 enum []string 17 } 18 19 // NewAwsCloudwatchMetricAlarmInvalidStatisticRule returns new rule with default attributes 20 func NewAwsCloudwatchMetricAlarmInvalidStatisticRule() *AwsCloudwatchMetricAlarmInvalidStatisticRule { 21 return &AwsCloudwatchMetricAlarmInvalidStatisticRule{ 22 resourceType: "aws_cloudwatch_metric_alarm", 23 attributeName: "statistic", 24 enum: []string{ 25 "SampleCount", 26 "Average", 27 "Sum", 28 "Minimum", 29 "Maximum", 30 }, 31 } 32 } 33 34 // Name returns the rule name 35 func (r *AwsCloudwatchMetricAlarmInvalidStatisticRule) Name() string { 36 return "aws_cloudwatch_metric_alarm_invalid_statistic" 37 } 38 39 // Enabled returns whether the rule is enabled by default 40 func (r *AwsCloudwatchMetricAlarmInvalidStatisticRule) Enabled() bool { 41 return true 42 } 43 44 // Severity returns the rule severity 45 func (r *AwsCloudwatchMetricAlarmInvalidStatisticRule) Severity() string { 46 return tflint.ERROR 47 } 48 49 // Link returns the rule reference link 50 func (r *AwsCloudwatchMetricAlarmInvalidStatisticRule) Link() string { 51 return "" 52 } 53 54 // Check checks the pattern is valid 55 func (r *AwsCloudwatchMetricAlarmInvalidStatisticRule) Check(runner *tflint.Runner) error { 56 log.Printf("[TRACE] Check `%s` rule for `%s` runner", r.Name(), runner.TFConfigPath()) 57 58 return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { 59 var val string 60 err := runner.EvaluateExpr(attribute.Expr, &val) 61 62 return runner.EnsureNoError(err, func() error { 63 found := false 64 for _, item := range r.enum { 65 if item == val { 66 found = true 67 } 68 } 69 if !found { 70 runner.EmitIssue( 71 r, 72 `statistic is not a valid value`, 73 attribute.Expr.Range(), 74 ) 75 } 76 return nil 77 }) 78 }) 79 }