github.com/jpreese/tflint@v0.19.2-0.20200908152133-b01686250fb6/rules/awsrules/models/aws_lb_target_group_invalid_protocol.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 // AwsLbTargetGroupInvalidProtocolRule checks the pattern is valid 14 type AwsLbTargetGroupInvalidProtocolRule struct { 15 resourceType string 16 attributeName string 17 enum []string 18 } 19 20 // NewAwsLbTargetGroupInvalidProtocolRule returns new rule with default attributes 21 func NewAwsLbTargetGroupInvalidProtocolRule() *AwsLbTargetGroupInvalidProtocolRule { 22 return &AwsLbTargetGroupInvalidProtocolRule{ 23 resourceType: "aws_lb_target_group", 24 attributeName: "protocol", 25 enum: []string{ 26 "HTTP", 27 "HTTPS", 28 "TCP", 29 "TLS", 30 "UDP", 31 "TCP_UDP", 32 }, 33 } 34 } 35 36 // Name returns the rule name 37 func (r *AwsLbTargetGroupInvalidProtocolRule) Name() string { 38 return "aws_lb_target_group_invalid_protocol" 39 } 40 41 // Enabled returns whether the rule is enabled by default 42 func (r *AwsLbTargetGroupInvalidProtocolRule) Enabled() bool { 43 return true 44 } 45 46 // Severity returns the rule severity 47 func (r *AwsLbTargetGroupInvalidProtocolRule) Severity() string { 48 return tflint.ERROR 49 } 50 51 // Link returns the rule reference link 52 func (r *AwsLbTargetGroupInvalidProtocolRule) Link() string { 53 return "" 54 } 55 56 // Check checks the pattern is valid 57 func (r *AwsLbTargetGroupInvalidProtocolRule) 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 fmt.Sprintf(`"%s" is an invalid value as protocol`, truncateLongMessage(val)), 75 attribute.Expr.Range(), 76 ) 77 } 78 return nil 79 }) 80 }) 81 }