github.com/jpreese/tflint@v0.19.2-0.20200908152133-b01686250fb6/rules/awsrules/models/aws_ec2_capacity_reservation_invalid_instance_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 // AwsEc2CapacityReservationInvalidInstancePlatformRule checks the pattern is valid 14 type AwsEc2CapacityReservationInvalidInstancePlatformRule struct { 15 resourceType string 16 attributeName string 17 enum []string 18 } 19 20 // NewAwsEc2CapacityReservationInvalidInstancePlatformRule returns new rule with default attributes 21 func NewAwsEc2CapacityReservationInvalidInstancePlatformRule() *AwsEc2CapacityReservationInvalidInstancePlatformRule { 22 return &AwsEc2CapacityReservationInvalidInstancePlatformRule{ 23 resourceType: "aws_ec2_capacity_reservation", 24 attributeName: "instance_platform", 25 enum: []string{ 26 "Linux/UNIX", 27 "Red Hat Enterprise Linux", 28 "SUSE Linux", 29 "Windows", 30 "Windows with SQL Server", 31 "Windows with SQL Server Enterprise", 32 "Windows with SQL Server Standard", 33 "Windows with SQL Server Web", 34 "Linux with SQL Server Standard", 35 "Linux with SQL Server Web", 36 "Linux with SQL Server Enterprise", 37 }, 38 } 39 } 40 41 // Name returns the rule name 42 func (r *AwsEc2CapacityReservationInvalidInstancePlatformRule) Name() string { 43 return "aws_ec2_capacity_reservation_invalid_instance_platform" 44 } 45 46 // Enabled returns whether the rule is enabled by default 47 func (r *AwsEc2CapacityReservationInvalidInstancePlatformRule) Enabled() bool { 48 return true 49 } 50 51 // Severity returns the rule severity 52 func (r *AwsEc2CapacityReservationInvalidInstancePlatformRule) Severity() string { 53 return tflint.ERROR 54 } 55 56 // Link returns the rule reference link 57 func (r *AwsEc2CapacityReservationInvalidInstancePlatformRule) Link() string { 58 return "" 59 } 60 61 // Check checks the pattern is valid 62 func (r *AwsEc2CapacityReservationInvalidInstancePlatformRule) Check(runner *tflint.Runner) error { 63 log.Printf("[TRACE] Check `%s` rule for `%s` runner", r.Name(), runner.TFConfigPath()) 64 65 return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { 66 var val string 67 err := runner.EvaluateExpr(attribute.Expr, &val) 68 69 return runner.EnsureNoError(err, func() error { 70 found := false 71 for _, item := range r.enum { 72 if item == val { 73 found = true 74 } 75 } 76 if !found { 77 runner.EmitIssue( 78 r, 79 fmt.Sprintf(`"%s" is an invalid value as instance_platform`, truncateLongMessage(val)), 80 attribute.Expr.Range(), 81 ) 82 } 83 return nil 84 }) 85 }) 86 }