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