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