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