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