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