github.com/jpreese/tflint@v0.19.2-0.20200908152133-b01686250fb6/rules/awsrules/models/aws_lambda_function_invalid_runtime.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 // AwsLambdaFunctionInvalidRuntimeRule checks the pattern is valid 14 type AwsLambdaFunctionInvalidRuntimeRule struct { 15 resourceType string 16 attributeName string 17 enum []string 18 } 19 20 // NewAwsLambdaFunctionInvalidRuntimeRule returns new rule with default attributes 21 func NewAwsLambdaFunctionInvalidRuntimeRule() *AwsLambdaFunctionInvalidRuntimeRule { 22 return &AwsLambdaFunctionInvalidRuntimeRule{ 23 resourceType: "aws_lambda_function", 24 attributeName: "runtime", 25 enum: []string{ 26 "nodejs", 27 "nodejs4.3", 28 "nodejs6.10", 29 "nodejs8.10", 30 "nodejs10.x", 31 "nodejs12.x", 32 "java8", 33 "java8.al2", 34 "java11", 35 "python2.7", 36 "python3.6", 37 "python3.7", 38 "python3.8", 39 "dotnetcore1.0", 40 "dotnetcore2.0", 41 "dotnetcore2.1", 42 "dotnetcore3.1", 43 "nodejs4.3-edge", 44 "go1.x", 45 "ruby2.5", 46 "ruby2.7", 47 "provided", 48 "provided.al2", 49 }, 50 } 51 } 52 53 // Name returns the rule name 54 func (r *AwsLambdaFunctionInvalidRuntimeRule) Name() string { 55 return "aws_lambda_function_invalid_runtime" 56 } 57 58 // Enabled returns whether the rule is enabled by default 59 func (r *AwsLambdaFunctionInvalidRuntimeRule) Enabled() bool { 60 return true 61 } 62 63 // Severity returns the rule severity 64 func (r *AwsLambdaFunctionInvalidRuntimeRule) Severity() string { 65 return tflint.ERROR 66 } 67 68 // Link returns the rule reference link 69 func (r *AwsLambdaFunctionInvalidRuntimeRule) Link() string { 70 return "" 71 } 72 73 // Check checks the pattern is valid 74 func (r *AwsLambdaFunctionInvalidRuntimeRule) Check(runner *tflint.Runner) error { 75 log.Printf("[TRACE] Check `%s` rule for `%s` runner", r.Name(), runner.TFConfigPath()) 76 77 return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { 78 var val string 79 err := runner.EvaluateExpr(attribute.Expr, &val) 80 81 return runner.EnsureNoError(err, func() error { 82 found := false 83 for _, item := range r.enum { 84 if item == val { 85 found = true 86 } 87 } 88 if !found { 89 runner.EmitIssue( 90 r, 91 fmt.Sprintf(`"%s" is an invalid value as runtime`, truncateLongMessage(val)), 92 attribute.Expr.Range(), 93 ) 94 } 95 return nil 96 }) 97 }) 98 }