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