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