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